I need to copy into F drive with the date as part of the new file name.

I want the files in F drive to have a file name and part of that name will be the daye.  This way I will have a new file in F with the date as part of the file name.  This way I can go back in time and use the correct file based on the date in the file name.
Don-WhiteAsked:
Who is Participating?
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:
This will add a YYYYMMDD to the file name.

copy C:\WorkKeys.mdb+ f:\WorkKeys_%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%.mdb

Open in new window

~bp
0
Don-WhiteAuthor Commented:
That code did not add the date to the filename
0
Bill PrewCommented:
Sorry, left the plus sign by mistake.

copy "C:\WorkKeys.mdb" "f:\WorkKeys_%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%.mdb"

Open in new window

~bp
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Don-WhiteAuthor Commented:
That did not work either.  I should be able to copy many file to f drive in a given day.  I guess the time must also be part of file name.

However, you last change did not work also.
0
Bill PrewCommented:
Worked fine for me here, and created a file called:

WorkKeys_20111219.mdb

did you use the line as I provided it, or do any changes to it?

es, we can add time to this, but need to understand why it's not working there.

can you also do these two commands at a command prompt and report back exactly what they display:

echo %DATE%
echo %TIME%

~bp
0
Don-WhiteAuthor Commented:
It did work, I just did not see it in the drivr f.  S

Show me the code with the time and see if I can have many copyies each time I execute the bat file.

Thanks,
0
Bill PrewCommented:
This code should add the time, and make sure single digit hours and months have leading zeros.  Resulting format will be:

WorkKeys_YYYYMMDD_hhmmss.mdb

set Stamp=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,8%
set Stamp=%Stamp: =0%
copy C:\WorkKeys.mdb+ f:\WorkKeys_%Stamp%.mdb

Open in new window

~bp
0
Bill PrewCommented:
Sorry, that plus sign jumped in there again, should be:

set Stamp=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,8%
set Stamp=%Stamp: =0%
copy C:\WorkKeys.mdb f:\WorkKeys_%Stamp%.mdb

Open in new window

~bp
0
Don-WhiteAuthor Commented:
I don't see the file.
0
Bill PrewCommented:
Sorry, forgot about the colons in the %TIME% variable, doh.

set Stamp=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,8%
set Stamp=%Stamp::=%
set Stamp=%Stamp: =0%
copy "C:\WorkKeys.mdb" "F:\WorkKeys_%Stamp%.mdb"

Open in new window

~bp
0
Don-WhiteAuthor Commented:
That did copy OK, but the date of the new file should be the current date.

The filename does have the date and time, but not the saved dated of file.
0
Bill PrewCommented:
Okay, this should handle that.

set Stamp=%DATE:~-4%%DATE:~-10,2%%DATE:~-7,2%_%TIME:~0,8%
set Stamp=%Stamp::=%
set Stamp=%Stamp: =0%
copy /B "C:\WorkKeys.mdb"+NUL "F:\WorkKeys_%Stamp%.mdb"

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
Don-WhiteAuthor Commented:
Thanks, again
0
Bill PrewCommented:
Welcome.

~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
Microsoft DOS

From novice to tech pro — start learning today.

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.