Copy multiple files with VBS

Hello Experts,
I am trying to move a number of files from one directory to another
using For Each and Next.  I have been trying to modify this code from anopther source and one thing I am not sure of is the item called objTFile which refers to the files in my source directory...don't I need to define this somewhere? It does not appear to be defined or referred to anywhere in the code I am looking at.  In any case this is not working and I really appreciate some help!
Thank you.  
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
strSourceFolder = "C:\Source"
strDestDir = "C:\ServeFiles"
For Each objSourceFile In objFSO.GetFolder(strSourceFolder).Files
objFile.Copy strDestDir & "\", True
Next

Open in new window

davidamAsked:
Who is Participating?
 
cyberkiwiCommented:
For Each objSourceFile In objFSO.GetFolder(strSourceFolder).Files
objSourceFile.Copy strDestDir & "\", True
Next
0
 
davidamAuthor Commented:
That did not seem to work...do I not need to define objSourceFile?
0
 
cyberkiwiCommented:
Unless you have option explicit, you shouldn't normally need to.
I think you need to give .Copy the destination name

Dim objFSO, objSourceFile, strSourceFolder, strDestDir
Set objFSO = CreateObject("Scripting.FileSystemObject")
strSourceFolder = "C:\Source"
strDestDir = "C:\ServeFiles"
For Each objSourceFile In objFSO.GetFolder(strSourceFolder).Files
objSourceFile.Copy strDestDir & "\" & objSourceFile.Name, True
Next
0
 
davidamAuthor Commented:
You were right the first time but I had a small typo in my first attempt...Thank you!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.