Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Jan 2003
    Location
    Central Florida, USA
    Posts
    505
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Copying/Moving Files (2003 sp2)

    This is so basic, I am ashamed to ask, but cannot find the answer by searching the archives. Is there a way to copy (or move) ALL files in a specified directory via Access/VBA?

    I am using:
    strFullPath = "O:Spreadsheetsbackups"
    strFileName = "dbTempTables.mdb"
    SourceFile = "C:Spreadsheets" & strFileName
    DestinationFile = strFullPath & strFileName
    FileCopy SourceFile, DestinationFile

    which works fine for copying individual files. However, I need to make a quarterly backup of files, and the file list is getting longer each time. So I would like to copy ALL the files into an archive directory on another server.

    I know I can put the list of files into a table and then loop through the table, but then anytime another file is needed

    Any help is greatly appreciated.

    kwvh

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Copying/Moving Files (2003 sp2)

    FileCopy doesn't support wildcards, but the CopyFile method of Scripting.FileSystemObject does. Use something like this:
    <code>
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.CopyFile "C:Spreadsheets*.mdb", "O:Spreadsheetsbackups"
    Set fso = Nothing
    </code>
    Note that FileSystemObject uses CopyFile, not FileCopy. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  3. #3
    4 Star Lounger
    Join Date
    Jan 2003
    Location
    Central Florida, USA
    Posts
    505
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Re: Copying/Moving Files (2003 sp2)

    WOW! That worked GREAT!

    And I found that fso.DeleteFile is available as well!


    Thanks Hans!

    Regards,
    Ken

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •