Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Set file time (hour & minute) to a variable

Hello
How to set file time (hour & minute) to a variable ?

I have a piece of complicated code in the bat file. Probably that was because there was no easy way in command.com to find time (hour & minute) of a file as Windows tend to show it in current language, etc. The code would rename existing file name from 200122.doc (i.e. named as per current date) to 200122-1736.doc (i.e. current date-hour&minute).

Now the relevant bat file is called from another btm file and very often (but not always) the result of this program seem to produce error "No" ("200122-no.doc") in the relevant language of my system.

--------------
for /f "tokens=2,3 delims=: " %%i in ('for %%f in ^(%dp%\%dmy%.doc^) do @echo %%~tf') do set ftime=%%i%%j
rename %dp%\%dmy%.doc %dmy%-%ftime%.doc
--------------

How to find hour and minute of the file stamp (lets say, creation or last edit)/write it to variable ?

thanks
 
You can get a file's date and time easily enough with
Code:
set ftime=%@filetime[%filename]

... but that does include an inconvenient colon. Remove it with something like
Code:
set ftime=%@strip[:,%@filetime[%filename]]
or
Code:
set ftime=%@replace[:,,%@filetime[%filename]]
 
Thanks
Where I refer to file name by variable - what should be the right syntax ?

This generates error
-----------
set ftime=%@strip[:,%@filetime[%dp%\%dmy%.doc]]
-----------
 

Similar threads

Replies
4
Views
2K
Back
Top