source code copy from directory to another

Download Source Code Copy From Directory to Another

If you can't read please download the document

Upload: gilang-on-wp

Post on 24-Sep-2015

214 views

Category:

Documents


0 download

DESCRIPTION

VB6

TRANSCRIPT

Public Function Copy_Files_Folder(ByRef strFrom_Path As String, ByRef strTo_Path As String) 'Copy all the files in a directory to another' Dim FSO As FileSystemObject Dim strFile As String 'Used to store the files that are found On Error GoTo err_hndl 'Simple check if the path is correct it hase to end with "\" else is added If Right$(strFrom_Path, 1) "\" Then strFrom_Path = strFrom_Path & "\" If Right$(strTo_Path, 1) "\" Then strTo_Path = strTo_Path & "\" 'find the files with the extension as *.* for all files in the current path strFile = Dir(strFrom_Path & "*.*") 'list all the file till dir return empty string Do While Len(strFile) Set FSO = New FileSystemObject With FSO 'check if the new folder exist if not create new one If Not .FolderExists(strTo_Path) Then .CreateFolder (strTo_Path) .CopyFile strFrom_Path & strFile, strTo_Path & strFile 'copy the files in the new directory End With Set FSO = Nothing strFile = Dir 'send the next file to variable File Loop Exit Functionerr_hndl: MsgBox "Error in Copy_Files_Folder()" & vbCrLf & Err.Number & ": " & Err.Description, vbCriticalEnd FunctionPrivate Sub Command1_Click() 'test button click Call Copy_Files_Folder(txtForm_Path.Text, txtTo_Path.Text)End Sub