Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Dear all
does someone explain me why the code
::-
echo off
setLocal EnableDelayedExpansionfor /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 EnableDelayedExpansionfor /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…

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.

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

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

As you know, much will depend on the date layou. In my case, this should work.
::== recreated.bat
@echo off
setLocal EnableDelayedExpansionfor /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.IVOoutput 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

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 varsbye
max

![]() |
![]() |
![]() |

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