Results 1 to 6 of 6

Thread: Copying multiple files from one directory to another

  1. #1

    Thread Starter
    Addicted Member LiquidRezin's Avatar
    Join Date
    Dec 2000
    Location
    Aliso Viejo, CA
    Posts
    176
    can someone please tell me how to copy all contents of one directory to another, then delete the contents of the original directory? here's what i basically want in dos commands...

    copy *.* c:\somedir
    delete *.*

    thanks

    Pete

  2. #2
    Guest
    Use the FileSystemObject.

    Code:
    Dim FSO As Object
    
    Private Sub Command1_Click()
    
         Set FSO = CreateObject("Scripting.FileSystemObject")
         FSO.MoveFolder "C:\somedir\", "C:\someotherdir\"
    
    End Sub

  3. #3
    Guest
    You could also use the SHFileOperation API function to move a folder to another folder.

    Code:
    Private Type SHFILEOPSTRUCT
       hWnd        As Long
       wFunc       As Long
       pFrom       As String
       pTo         As String
       fFlags      As Integer
       fAborted    As Boolean
       hNameMaps   As Long
       sProgress   As String
     End Type
      
    Private Const FO_MOVE = &H1
    Private Const FO_COPY = &H2
    Private Const FO_DELETE = &H3
    Private Const FO_RENAME = &H4
    
    Private Const FOF_SILENT = &H4
    Private Const FOF_RENAMEONCOLLISION = &H8
    Private Const FOF_NOCONFIRMATION = &H10
    Private Const FOF_SIMPLEPROGRESS = & H100 
    Private Const FOF_ALLOWUNDO = &H40
    
    
    Private Declare Function SHFileOperation _
        Lib "shell32.dll" Alias "SHFileOperationA" _
        (lpFileOp As SHFILEOPSTRUCT) As Long
    
    
    Private Sub Command1_Click()
    Dim SHF As SHFILEOPSTRUCT
    Dim lret As Long
    
    SHF.wFunc = FO_MOVE
    SHF.hWnd = Me.hWnd
    SHF.pFrom = "C:\somedir\*.*"
    SHF.pTo = "C:\someotherdir\"
    SHF.fFlags = FOF_SILENT
    
    lret = SHFileOperation(SHF)
    
    'Returns 0 if successful
    
    If lret <> 0 Then
        MsgBox "Error"
    End If
    End Sub

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Private Sub Form_Load()
    'Using FSO copy the contents of a floppy to a folder on a different drive
    'copies files and folders seperately as they use different vehicles
    '
    Dim FSO As Object
    On Error GoTo NOFSO
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    On Error Resume Next
    
    'make sure the directory exists and if not create it
    If Dir("C:\AAA", vbDirectory) = "" Then
        MkDir ("C:\AAA")
     Else
    End If
    
    FSO.CopyFile "c:\AABBCC\*", "C:\AAA\", True
    FSO.CopyFolder "c:\AABBCC\*", "C:\AAA\", True
    
    'Using fso to delete a directory
    FSO.DeleteFolder "c:\AABBCC"
    
    Set FSO = Nothing
    Exit Sub
    NOFSO:
    MsgBox "FSO CreateObject Failed"
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5

    Thread Starter
    Addicted Member LiquidRezin's Avatar
    Join Date
    Dec 2000
    Location
    Aliso Viejo, CA
    Posts
    176

    Re: <?>

    Originally posted by HeSaidJoe
    Code:
    Private Sub Form_Load()
    'Using FSO copy the contents of a floppy to a folder on a different drive
    'copies files and folders seperately as they use different vehicles
    '
    Dim FSO As Object
    On Error GoTo NOFSO
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    On Error Resume Next
    
    'make sure the directory exists and if not create it
    If Dir("C:\AAA", vbDirectory) = "" Then
        MkDir ("C:\AAA")
     Else
    End If
    
    FSO.CopyFile "c:\AABBCC\*", "C:\AAA\", True
    FSO.CopyFolder "c:\AABBCC\*", "C:\AAA\", True
    
    'Using fso to delete a directory
    FSO.DeleteFolder "c:\AABBCC"
    
    Set FSO = Nothing
    Exit Sub
    NOFSO:
    MsgBox "FSO CreateObject Failed"
    End Sub
    great, thanks guys for the code, however i dont want to delete the directory im moving the files from, just the files inside the directory...how can i do this?

    Pete

  6. #6

    Thread Starter
    Addicted Member LiquidRezin's Avatar
    Join Date
    Dec 2000
    Location
    Aliso Viejo, CA
    Posts
    176
    hehe it's too early in the morning, i forgot about the kill function for my post above but thanks guys for the posts, they helped tremendously

    Pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width