Adding Datestamp to Folder

I

ieuan.jones

Hi I need to be able via a bat file rename a file where it keeps the
original filename if possible but adds the current date to the folder
(or if needs be just rename the folder to the current date). Can anyone
help??

Regards

YingYang
 
D

Dmitry Anikin

Hi I need to be able via a bat file rename a file where it keeps the
original filename if possible but adds the current date to the folder
(or if needs be just rename the folder to the current date). Can anyone
help??
rename any folder to current date:
ren "any folder" %date%
 
D

Dmitry Anikin

rename any folder to current date:
ren "any folder" %date%

It probably won't work if you have slash as date separator.
I have dot, so it's OK for me.

You could make it this way to skip separators:
ren "any folder" %date:~-2%%date:~3,2%%date:~,2%
But, again it depends on your system's date format.
 
I

ieuan.jones

Thanks ever so much....I should paid more attention in school when I
did dos programming
 
I

ieuan.jones

Out of curiosity is there a way to have the time on as well. to cut a
long storey short I have to find a way to allow someone to update a
folder by renaming the original one with the date and time (for
archiving) and then moving a new folder to the old location the latter
is easy but having thought about it it the folder gets 'updated more
than once a day then there will be issues with just the date on the
renamed folder.
 
D

Dmitry Anikin

Out of curiosity is there a way to have the time on as well. to cut a

Sure, just use %time%.
You'll have to remove colons and milliseconds.
%time:~,2%%time:~3,2%%time:~6,2% will do
fine if your time is military 24-hour style, with
am/pm it may be a little more complicated.

By the way, if you use %date% and %time% more
than once, better assign it first to a variable, then
extract substrings from that variable to ensure
consistent value (%time% value changes every
10 milliseconds, you know)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top