Hello,
I have a batch file which copies a file and appends today's date. I would like to do the same, but append the last modified date. Can someone help?
Here is my existing code to append today's date:
@echo off
set today=%date:~6,4%-%date:~3,2%-%date:~0,2%
:loop
copy %1 "%~dpn1_%today%%~x1"
if .%2==. goto end
shift
goto loop
:end
Page 1 of 1
Batch File Date Help
#2
Posted 01 August 2012 - 05:03 AM
s2nrbald, on 01 August 2012 - 03:04 AM, said:
Can someone help?
Yes.
http://homepage.ntlw...no-answers.html
Easier to get the "last modified date" is to actually DIR the file.
Say that you have a file c:\test.txt
Dir C:\test.txt
will show you something like (this is my Italian interface):
C:\>dir test.txt
Il volume nell'unità C non ha etichetta.
Numero di serie del volume: C08C-CFD9
Directory di C:\
19/12/2011 12:05 62 Test.txt
1 File 62 byte
0 Directory 147.178.754.048 byte disponibili
Then try:
Quote
C:\>dir /TC test.txt
to get the Creation date)
Quote
C:\>dir /TA test.txt
This is the (last) Access date.
Same goes for /TW for (last) Write date
Parsing any of these three commands results amounts more or less to:
@ECHO OFF
FOR /F "tokens=1,2,3 delims=/ " %%A IN ('DIR /TA C:\test.txt ^| FIND /I "test.txt"') DO (
SET A_Day=%%A
SET A_Month=%%B
SET A_Year=%%C
)
SET A_
But see this thread also
http://www.msfn.org/...d-created-date/
jaclaz
This post has been edited by jaclaz: 01 August 2012 - 05:04 AM
#3
Posted 01 August 2012 - 08:43 AM
Thank you for your support.
Now a new question. How do I get your input into the form required? For my previous code mentioned above, I saved this file as backup.bat. I then have a shortcut to this on my desktop. When I drag a file to the shortcut, it automatically adds a copy of the file on the desktop with today's date added. In this new example I would like to do something similar (add a shortcut to this new .bat file, drag some file to it, and then let it create a copy of it with the last modified date appended.) Taking it one step further, it would be nice if it also could just rename the file, without even making a copy.
Now a new question. How do I get your input into the form required? For my previous code mentioned above, I saved this file as backup.bat. I then have a shortcut to this on my desktop. When I drag a file to the shortcut, it automatically adds a copy of the file on the desktop with today's date added. In this new example I would like to do something similar (add a shortcut to this new .bat file, drag some file to it, and then let it create a copy of it with the last modified date appended.) Taking it one step further, it would be nice if it also could just rename the file, without even making a copy.
#4
Posted 01 August 2012 - 09:53 AM
s2nrbald, on 01 August 2012 - 08:43 AM, said:
Thank you for your support.
You are welcome
s2nrbald, on 01 August 2012 - 08:43 AM, said:
Now a new question. How do I get your input into the form required?
An interesting one.
Possibly adapting the example snippet to what you want to do
I took the original request as:
I want to write a new batch file, similar to the one I already wrote, but I don't know how to get the Last Modified date/time of file; how can I do this?
And not as:
I had someone write for me a batch file.
I need someone to write a new one for me with these other features: ......
Had you actually READ
http://www.msfn.org/...post__p__999477
Since "your" batch already uses variable expansion:
http://www.robvander...e.com/ntfor.php
and the t element of an expanded variable represents date/time (last modified one).
"Your" batch becomes nicely:
Quote
@echo off
set LM_date=%~t1
set today=%LM_date:~6,4%-%LM_date:~3,2%-%LM_date:~0,2%
:loop
copy %1 "%~dpn1_%today%%~x1"
if .%2==. goto end
shift
goto loop
:end
set LM_date=%~t1
set today=%LM_date:~6,4%-%LM_date:~3,2%-%LM_date:~0,2%
:loop
copy %1 "%~dpn1_%today%%~x1"
if .%2==. goto end
shift
goto loop
:end
The general idea was to give you some missing pieces (of various puzzles
jaclaz
#5
Posted 01 August 2012 - 01:05 PM
Please also bear in mind that in may be prudent to incorporate a check that the 'file' does not already have that date incorporated within its file name. It may then also be necessary to ensure that conflicts of files modified more than once in any day are catered for adequately in your copy procedure.
- ← my node won't work
- Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
- Edit a ISO file with a Batch file. →
Share this topic:
Page 1 of 1



Help
Back to top









