Computing.Net > Forums > Programming > append creation date to filename

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

append creation date to filename

Reply to Message Icon

Name: maxbre
Date: December 11, 2007 at 08:21:21 Pacific
OS: win2k
CPU/Ram: 1 gb
Product: fujitsu
Comment:

Dear all

does someone explain me why the code

::-
echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir /b/a-d *.txt') do (
copy %%a %%~Na_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt
)

::-

is working fine by adding at the end of the filename the string “_aaaammgg”

but the code

::-
@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir /b/tc *.txt') do (
copy %%a %%~Na_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt
)
::-

note that the main difference is in (‘dir /b /tc*.txt') because I would like to append the creation date of the file (not the actual one); I know this is not a general (good) code because it can be applied just to certain date and time layouts (mine!) but I still can not figure out why it can not append the creation date of file to the file name; is it a matter of the different paramenters given to the dir command or am I completely off the main track?

Thanks again

max

PS: I’ve been checking in the forum and the subject I posted right now it is certainly not new but I did not find a solution yet…




Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: December 11, 2007 at 13:48:08 Pacific
Reply:

does someone explain me why the code
. . .
is working fine . . . but the code
. . .
[doesn't work]

Answer: %Date% is the CURRENT date, and it has no relation to anything happening in the FOR statement. Also, the switch /Tc does indeed display the creation time, but the switch /B suppresses this from showing.

%%~Ta would give you the modified time of the file, but not the created file. If you're going to do this in Command Script, you need to use nested FORs.


0

Response Number 2
Name: maxbre
Date: December 11, 2007 at 23:57:41 Pacific
Reply:

Hi razor
You are perfectly right, yesterday I was at the end of a long, long day and now I realise I was completely missing the point!
I’ll post later on about the results of my attempts
bye
max


0

Response Number 3
Name: maxbre
Date: December 12, 2007 at 00:26:22 Pacific
Reply:

and what about this (refs in this forum)

for /f "tokens=1,2,3,4,5,6,* skip=5 delims=:/ " %%a in ('dir /t /c *.* ^|find "/"') do (
copy "%%g" "%%c%%b%%a%%d%%e%%g"
)

I think it is quite close to the point but somehow it is missing something because it says "could not find the path..."

still to explore the hint by razor

cheers

m


0

Response Number 4
Name: Mechanix2Go
Date: December 13, 2007 at 19:32:03 Pacific
Reply:

As you know, much will depend on the date layou. In my case, this should work.

::== recreated.bat
@echo off
setLocal EnableDelayedExpansion

for /f "tokens=1,4 delims= " %%a in ('dir /tc *.ivo^|find "."') do (
echo copy %%b x:\mystuff\%%a%%b
)
::============================

output of 'dir /tc *.ivo^|find "."'

05-11-2007 19:01 263 SFN.IVO
13-12-2007 18:32 305 DELSSTR.IVO
13-12-2007 21:00 1,432 LOTTO2.IVO
10-12-2007 23:01 1,942 STRIP3.IVO

output of bat

copy SFN.IVO x:\mystuff\02-11-2007SFN.IVO
copy DELSSTR.IVO x:\mystuff\13-12-2007DELSSTR.IVO
copy LOTTO2.IVO x:\mystuff\13-12-2007LOTTO2.IVO
copy STRIP3.IVO x:\mystuff\10-12-2007STRIP3.IVO



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 5
Name: maxbre
Date: December 14, 2007 at 00:41:56 Pacific
Reply:

thanks m2
as usual you are of great help, now I'm studing the bat carefully;
I'm always a bit in trouble with the passing of tokens to vars

bye
max


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: append creation date to filename

use creation date in renaming file www.computing.net/answers/programming/use-creation-date-in-renaming-file/15094.html

Batch file append date to file nm? www.computing.net/answers/programming/batch-file-append-date-to-file-nm/18658.html

Batch file to append created date www.computing.net/answers/programming/batch-file-to-append-created-date/14993.html