Script to copy files to a folder

Nick Collins
Nick Collins used Ask the Experts™
Looking for a script that can copy files into a folder...

The folder name is today’s date based on the format

So the folder name will change everyday, so the script needs to be based on the folder name of today’s date.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IT / Software Engineering Consultant
Top Expert 2016
Here is a starting point.

Option Explicit

' Define used variables
Dim objFSO, strDateStamp, strFromDir, strToDir

' Specify from and to folder paths (MUST EXIST ALREADY!)
strFromDir = "c:\temp\fromdir"
strToDir = "c:\temp\todir"

' Create file system object
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

' Build date stamp in YYYYMMDD format
strDateStamp = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2)

' Now create desired folder
objFSO.CreateFolder(strToDir & "\" & strDateStamp)

' Move all PDF files to new folder
objFSO.CopyFile strFromDir & "\*.pdf", strToDir & "\" & strDateStamp

Open in new window



Thank you for the script...

I created the script and ran it with the command line - Files have moved to the correct folder as planned.

I have set up it under the task scheduler to runs the VBS script but for some reason it is hanging...

Any ideas?
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Hard to answer without knowing how you set up the Scheduled Task.

Did you specify the full path to the VBS file, and quote it if there are spoaces in it?

Are you launching it with CSCRIPT in the Scheduled Task?  

And running only when user is signed on?  

No error code in Task Scheduler, it just says "Running"?

You may need to put some logging into the VBS script to see if it even gets started (my guess would be it isn't since it's pretty simple).



I think I have solved it now lol!

I missed out cscript on the scheduler..

If I wanted to a log file to the task scheduler, how do I do this?
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

If you want to log information from the VBS script itself, then you could use a technique like I did in this solution:

It's important to note that the messages written to the log file include an Open, Write, and Close of the log file for each message.  This is important since if the VBS file errors out during execution and just aborts you want to make sure all previous message were fully written to the log file and it was cleanly closed.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial