How to Copy All Files in Visual Basic 6 with the Archive Attribute

Written by declan maher
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Copy All Files in Visual Basic 6 with the Archive Attribute
Code to copy files in Visual Basic 6 (ANSI image by DBX 60 from Fotolia.com)

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:
Easy

Other People Are Reading

Things you need

  • Visual Basic 6

Show MoreHide

Instructions

  1. 1

    Open your Visual Basic editor program.

  2. 2

    Create a new file by clicking on "File," then "New."

  3. 3

    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.

  4. 4

    Set the source folder and the destination folder where you will copy the files:

    strSourceFolder = "c:\MyImportantData"

    strDestFolder = "c:\MyBackupFolder"

  5. 5

    Open the loop for all the files in the source directory:

    For Each objFiles In objFSO.GetFolder(strSource).Files

  6. 6

    Check that each file has an attribute set to archive and close the loop opened above:

    If objFiles.attributes and 32 Then

  7. 7

    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

  8. 8

    Close the loop and end the Sub:

    Else

    ' Archive atribute not set
    

    End If

    End Sub

  9. 9

    Save the file as an .exe file and run the file to copy all the archived files.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.