| Description:Copy all the files from one directory to another. Here is a function that will copy all the files from the source directory to the destination director. Function CopyDir(sSourceDir As String, sDestDir As String) As Integer CopyTheDirectory = True On Error GoTo DirCopy_err Dim SourceFile As String Dim DestinationFile As String 'Endure src and dest directories have trailing slash If Right(sSourceDir, 1) <> "\" Then sSourceDir = sSourceDir & "\" If Right(sDestDir, 1) <> "\" Then sDestDir = sDestDir & "\" 'Call dir for the first file SourceFile = Dir(sSourceDir & "*.*") 'returns first file matching *.* 'Keep calling Dir again without arguments to return the next file in the same directory. Do Until SourceFile = "" DestinationFile = sDestDir & sParseFileName(SourceFile) FileCopy sSourceDir & SourceFile, DestinationFile SourceFile = Dir Loop Exit Function DirCopy_err: Dim sErrMsg As String Select Case Err Case 61 sErrMsg = "Disk Full" Case 71 sErrMsg = "Disk Not Ready" Case 76 sErrMsg = "Path not found" Case 70 sErrMsg = "Permission denied" End Select MsgBox sErrMsg, 48, "Cannot Copy File(s)!" CopyTheDirectory = False 'Something failed End Function Function sParsePath (sPathIn As String) As String Dim I As Integer For I = Len(sPathIn) To 1 Step -1 If InStr(":\", Mid$(sPathIn, I, 1)) Then Exit For Next sParsePath = Left$(sPathIn, I) End Function |
CopyDir |
Express News India | Freelance ecommerce web development India