Script to copy files to a folder

Looking for a script that can copy files into a folder...

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

So the folder name will change everyday, so the script needs to be based on the folder name of today’s date.
Nick CollinsAsked:
Who is Participating?
 
Bill PrewConnect With a Mentor Commented:
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


»bp
0
 
Nick CollinsAuthor Commented:
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?
0
 
Bill PrewCommented:
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).


»bp
0
 
Nick CollinsAuthor Commented:
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?
0
 
Bill PrewCommented:
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.


»bp
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.