Solved

copying file with current date

Posted on 2014-01-21
6
394 Views
Last Modified: 2014-01-21
Support,

Whenever I'm trying to copy the file with current date in the batch scripting it's copied like this..

Copy "\\<servername>\d$\kumar.srf" "\\<servername>\d$\kumar%date:~-10,2%%date:~-7,2%%date:~-4,4%.srf"
 
 1 file(s) copied


it's copied like this:

kumar--------.srf
0
Comment
Question by:iamsateesh
6 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 39798037
Open a command prompt and run the following:

C:\>  echo %date:~-10,2%%date:~-7,2%%date:~-4,4%

Open in new window

What is the output of the above command?  (the command begins with "echo")
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39798042
Use a better way of getting the date perhaps.

What do you get from

echo %date%

set d=%date:/=%

 will remove / from the date into variable d

set d=%~d,4%
echo use %d% in your copy now.

that will remove first 4 chars if date is Mon 21/01/2014 etc.

But better is to use more reliable date that doesn't matter what the user has set for date format.  Try this:

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_1153-Using-dates-in-batch-files-scripts.html

Steve
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 39798064
While it is true that the specific format of the %DATE% variable can vary depending on Windows settings, you seemed to indicate that you are getting "--------" as the result of "%date:~-10,2%%date:~-7,2%%date:~-4,4%" and that doesn't make sense.

Are you sure you aren't changing the DATE environment variable someplace in your code to have a lot of dashes in it?

~bp
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 33

Expert Comment

by:knightEknight
ID: 39798065
Something to try:

copy  "\\<servername>\d$\kumar.srf"  "\\<servername>\d$\kumar%date:~4,2%%date:~7,2%%date:~10,4%.srf"

Open in new window

This just switches out the negative values for positive values that correspond to the same position(s) in the date string.
0
 

Author Comment

by:iamsateesh
ID: 39798166
it's came like this:

kumar---.srf
0
 
LVL 52

Accepted Solution

by:
Bill Prew earned 125 total points
ID: 39798175
And of course, with more and more systems having powershell on them, you can leverage it to keep things simple and do:

for /f %%A in ('powershell get-date -format "{yyyyMMdd}"') do set Stamp=%%A
Copy "\\<servername>\d$\kumar.srf" "\\<servername>\d$\kumar%Stamp%.srf"

Open in new window

~bp
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now