Connecting Tech Pros Worldwide Forums | Help | Site Map

Moving multiple files from one folder to another

Member
 
Join Date: Mar 2007
Posts: 46
#1: Apr 22 '09
Hi,

I am using Access to pull in some excel spreadsheets and create tables from them. They appear in one particular subdirectory. However after these spreadsheets are in Access, I'd like to move them all to a new folder. I have been able to code the program to move one - but I need them all to be moved over. Here's what I did:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Command59_Click()
  3. Dim fso, f2
  4.  
  5. Set fso = CreateObject("Scripting.FileSystemObject")
  6. Set f2 = fso.GetFile("R:\Projects\ExcelVersion\0012BASE.xls")
  7. f2.Move ("R:\Projects\ProcessedData\")
  8.  
  9. End Sub
  10.  
  11.  
What do I need to do to move all the documents in the folder:
R:\Projects\ExcelVersion\ to folder:
R:\Projects\ProcessedData\

Expert
 
Join Date: Jul 2008
Location: Maryland
Posts: 1,176
#2: Apr 22 '09

re: Moving multiple files from one folder to another


You could try out the Application.FileSearch and its .FoundFiles property. I haven't used it myself but it goes something like this:
Expand|Select|Wrap|Line Numbers
  1. Dim strFileName as String
  2. With Application.FileSearch
  3.     .LookIn = "C:\My Documents" 'your directory here
  4.     For i = 1 To .FoundFiles.Count
  5.        strFileName = FoundFiles(i)
  6.        'Do Stuff
  7.     Next i
  8. End With
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#3: Apr 23 '09

re: Moving multiple files from one folder to another


You could use :
Expand|Select|Wrap|Line Numbers
  1. Call Shell("CMD /C MOVE R:\Projects\ExcelVersion\*.* R:\Projects\ProcessedData\")
This will run asynchronously though (Your code will continue running after the command has been started, and will not wait until it has finished). For a synchronous version see ShellWait() Function.
Reply