Results 1 to 3 of 3

Thread: How to copy a directory

  1. #1

    Thread Starter
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    Thumbs up How to copy a directory

    \hi...
    here I was strucked with Directory copying...
    Whats my problem was "How can I copy A directory and all its sub directories,files from one location to another location.."
    Will filecopy helps me any more??/

    Please help me..


    Srikanth.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: How to copy a directory

    Here is a quick sample for you:
    Code:
    Option Explicit
    
    Private Type SHFILEOPSTRUCT
            hwnd As Long
            wFunc As Long
            pFrom As String
            pTo As String
            fFlags As Integer
            fAnyOperationsAborted As Long
            hNameMappings As Long
            lpszProgressTitle As String '  only used if FOF_SIMPLEPROGRESS
    End Type
    
    Private Const FOF_MULTIDESTFILES = &H1
    Private Const FOF_CONFIRMMOUSE = &H2
    Private Const FOF_SILENT = &H4
    Private Const FOF_RENAMEONCOLLISION = &H8
    Private Const FOF_NOCONFIRMATION = &H10
    Private Const FOF_WANTMAPPINGHANDLE = &H20
    Private Const FOF_CREATEPROGRESSDLG = &H0
    Private Const FOF_ALLOWUNDO = &H40
    Private Const FOF_FILESONLY = &H80
    Private Const FOF_SIMPLEPROGRESS = &H100
    Private Const FOF_NOCONFIRMMKDIR = &H200
    
    Private Const FO_MOVE = 1
    Private Const FO_COPY = 2
    Private Const FO_DELETE = 3
    Private Const FO_RENAME = 4
    
    Private Declare Function SHFileOperation Lib "shell32.dll" (lpFileOp As SHFILEOPSTRUCT) As Long
        
    Public Function CopyFolder(ByVal strSource As String, ByVal strDest As String) As Boolean
    '==========================================================================================
    Dim varFOS As SHFILEOPSTRUCT
        With varFOS
            .fFlags = FOF_NOCONFIRMATION Or FOF_SILENT Or FOF_NOCONFIRMMKDIR
            .wFunc = FO_COPY
            .pFrom = strSource
            .pTo = strDest
        End With
        Call SHFileOperation(varFOS)
        CopyFolder = (varFOS.fAnyOperationsAborted = 0)
    End Function
    
    'usage:
    CopyFolder "c:\temp", "c:\temp2"

  3. #3
    New Member
    Join Date
    Nov 2004
    Location
    Houston, TX
    Posts
    7

    Re: How to copy a directory

    Or you might try the CopyFolder method of the FileSystemObject object.
    JohnD

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