Results 1 to 5 of 5
  1. #1
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904

    Moving ALL Files in a Folder

    This seems like it should be such a silly little thing, but for some reason I cannot get it to work.



    At the end of a VBA procedure, I want to move all my input files into an archive folder. This is what I am trying:
    Code:
        Dim myFromPath as String
        Dim myToPath as String
    
        myFromPath = "G:\Input\*.*"
        myToPath = "G:\Input\Archive"
    
        FileCopy myFromPath, myToPath
        Kill myFromPath
    It is returning an error that says: Run-time error 52: Bad file name or number.
    I verified that all the folders and file names are correct, and that I have read/write rights to all the directories (I can manually copy and move files into these directories).

    Can anyone tell what I am doing wrong?

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I usually do file movement with filesystemobject commands but have you tried

    myToPath = "G:\Input\Archive\"

  3. #3
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I usually do file movement with filesystemobject commands but have you tried

    myToPath = "G:\Input\Archive\"
    Yes, I tried numerous variations, including that one. I also tried:
    Code:
    myToPath = "G:\Input\Archive\*.*"
    If you have other code using FileSystemObject commands, I am open to that too!

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Code:
    Dim fs
    Dim sSourceDir As String
    Dim sTargetDir As String
    
    Set fs = CreateObject("scripting.filesystemobject")
    
    sSourceDir = "<Sourcedir>\*.*"
    sTargetDir = "<Targetdir>"
    
    fs.copyfile sSourceDir, sTargetDir
    
    Set fs = Nothing

  5. #5
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Beautiful! I just added the KILL statment at the end, and it does exactly what I need it to.

    Thanks!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Transfer all text files in a specified folder
    By rtackett in forum Programming
    Replies: 4
    Last Post: 09-10-2012, 11:50 AM
  2. Number of files in a folder.
    By Iain in forum Reports
    Replies: 3
    Last Post: 06-17-2012, 01:53 PM
  3. Replies: 13
    Last Post: 05-23-2012, 12:30 AM
  4. Copy files into specific folder
    By Jan22 in forum Access
    Replies: 12
    Last Post: 04-17-2012, 08:27 AM
  5. show filters files form a Folder
    By jimmyp75 in forum Programming
    Replies: 5
    Last Post: 03-16-2011, 12:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums