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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cyberkiwiCommented:
For Each objSourceFile In objFSO.GetFolder(strSourceFolder).Files
objSourceFile.Copy strDestDir & "\", True
Next
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.