Results 1 to 5 of 5

Thread: Copying directories

  1. #1

    Thread Starter
    Addicted Member icemanmt78's Avatar
    Join Date
    May 2000
    Posts
    142

    Exclamation

    In VB/VBA How do i copy a whole Directory from one location to another???????????????

  2. #2
    Hyperactive Member theman32x's Avatar
    Join Date
    May 2000
    Location
    New Jersey, USA
    Posts
    305
    look on the help for "filecopy"
    it might be what ur looking for

  3. #3

    Thread Starter
    Addicted Member icemanmt78's Avatar
    Join Date
    May 2000
    Posts
    142

    Angry No Luck

    I want to copy the whole directory and its contents to the same tree structure in a dirfferent location.

    I have noticed that i could use the FSO object to do so but VBA doesn't ref this object.

    e.g
    Set FSO = CreateObject("Scripting.FileSystemObject")

    Can i import a dll that allow to to reference the library containing the FSO object and its methods??

  4. #4
    Guest
    Use the SHFileOperation api function to do this.

    Code:
    '********Put this in a module********
    
    Public 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
      
    Public Const FO_MOVE = &H1
    Public Const FO_COPY = &H2
    Public Const FO_DELETE = &H3
    Public Const FO_RENAME = &H4
    
    Public Const FOF_SILENT = &H4
    Public Const FOF_RENAMEONCOLLISION = &H8
    Public Const FOF_NOCONFIRMATION = &H10
    Public Const FOF_SIMPLEPROGRESS = & H100 
    Public Const FOF_ALLOWUNDO = &H40
    
    
    Public Declare Function SHFileOperation _
        Lib "shell32.dll" Alias "SHFileOperationA" _
        (lpFileOp As SHFILEOPSTRUCT) As Long
    Put this is a for under a button call Command1.


    Code:
    Private Sub Command1_Click()
    Dim SHF As SHFILEOPSTRUCT
    Dim lret As Long
    
    SHF.wFunc = FO_COPY
    SHF.hWnd = Me.hWnd
    SHF.pFrom = "c:\windows\desktop\tiff\*.*"
    SHF.pTo = "c:\windows\desktop\test\"
    SHF.fFlags = FOF_SILENT
    
    lret = SHFileOperation(SHF)
    
    'Returns 0 if successful
    
    If lret <> 0 Then
        MsgBox "Error"
    End If
    
    
    End Sub

    Or you can use FileSystemObject.

    Code:
    Dim FSO as Object
    
    Private SubForm_Load()
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    'Syntax is object.MoveFolder source, destination
    
    FSO.MoveFolder "c:\myFolder\","c:\backup\myfolder\"
    
    End Sub

  5. #5

    Thread Starter
    Addicted Member icemanmt78's Avatar
    Join Date
    May 2000
    Posts
    142

    Unhappy

    Thanks, that works fine


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