Link to home
Start Free TrialLog in
Avatar of derekstattin
derekstattin

asked on

Adding the date to a file name .CMD funcltion

Shift-1 helped me this code.
I would like to add the date rather than a just adding a 1 to the file name

@echo off
setlocal
 
set folder=C:\myfolder
 
for /F "tokens=*" %%G in ('dir "%folder%" /A:-D /B') do (
 echo F|xcopy "%folder%\%%G" "%folder%\%%~nG1%%~xG" /C /H /R /Y
)

e.g.
contained in myfolder
test.txt
test2.txt
after running the .cmd
the folder would contain

test.txt
test2.txt
test-10-7-08.txt
test2-10-7-08.txt

thanks for the help


SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of derekstattin
derekstattin

ASKER

The results I got from sirbounty's code is the creation of test-Tu- 1-2008 .txt when the .cmd file is run on a my folder containing test.txt

Is this because of the time zone? I am tijuana/pacific coast US time zone

I could not get any results from si_shamil code, may I need to change something on my end?

thanks
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sir Bounty,

Thank you for the two examples. The first example works as expected.

The second example create a new folder

When I  run the .cmd file, a new folder named test-10 is created in myfolder (where test.txt contained)

Thanks for the help, I am going to post another question related to these results
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial