Copying a directory of files can be automated in Visual Basic 6 using the File System Object, which is included as an object in Visual Basic.
- Skill level:
Other People Are Reading
Things you need
- Visual Basic 6
Open your Visual Basic editor program.
Create a new file by clicking on "File," then "New."
Create an instance of the FileSystemObject by using the following code:
Dim fso, file
Set objFSO = CreateObject("Scripting.FileSystemObject")
This code calls a built-in object in Visual Basic 6.
Set the source folder and the destination folder where you will copy the files:
strSourceFolder = "c:\MyImportantData"
strDestFolder = "c:\MyBackupFolder"
Open the loop for all the files in the source directory:
For Each objFiles In objFSO.GetFolder(strSource).Files
Check that each file has an attribute set to archive and close the loop opened above:
If objFiles.attributes and 32 Then
Add the code to copy all the archive files from the source to the destination:
objFSO.CopyFile strSource & "\" & objFiles.Name, strDestination & "\" & objDir.Name & "\" & objFiles.Name, OVER_WRITE_FILES
objFiles.attributes = objFiles.attributes - 32
Close the loop and end the Sub:
' Archive atribute not set
Save the file as an .exe file and run the file to copy all the archived files.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for