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?

[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.

Bill PrewCommented:
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

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