1.

Solve : Time/Date Stamp on Filenames using Batch?

Answer» HEY all. First POST here.

I'm looking for a way to run a batch against pre-existing files and folders, and rename them both to include a date/time stamp. The original and end result below.

Begin with:
abc00.eob
abc01.eob
/abc00 (folder)
/abc01 (folder)

Change to:
abc00_20050318_09.33.45.eob
abc01_20050318_09.33.45.eob
/abc00_20050318_09.33.45
/abc01_20050318_09.33.45

The exact formatting of the date/time shown above is not critical. The purpose here is so that file names and folders are unique, but every file has a folder with a matching name. The file "abc00.eob" could be created a few times a day, many days in a row, and I need to keep them unique. This all has to be built into a .bat file.

Thanks for any advice.This may WORK for you. Feel free to make any cosmetic changes as required:

@echo off
For /f "tokens=1-7 delims=:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (
For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (
set dow=%%i
set %%a=%%j
set %%b=%%k
set %%c=%%l
set hh=%%m
set min=%%n
set ss=%%o
)
)

For /f %%g in (*.* *.) do ren %%g %%g%%mm%%dd%%yy%%hh%%mm%%ss%.*

Hope this helps.
All that it returns is "The system cannot find the file *.*." I only sort of understand what this batch is doing... am I not feeding it something properly? Thanks!That was probably my fault. I took the date split logic from an old batch file but wrote the rename from memory. Try it this way:

For /f %%g in (dir /b *.*) do ren %%g %%g%%mm%%dd%%yy%%hh%%mm%%ss%.*

For /f %%g in (dir /b *.) do ren %%g %%g%%mm%%dd%%yy%%hh%%mm%%ss%.*

Good luck.

PS. If your machine can handle the date/time logic, you should consider using Windows Script. It's a lot easier, and definantly more readable.We're getting closer. I took those last lines and replaced them with a simple REN because I know the name of the files I'll be dealing with. Also, with %%mm%%dd%%yy.... It prints a LITERAL string for the FILENAME %g%mm%dd%yy....

If I take the extra leading % out (from %%mm), I get the values, but they are all seperated by a space: 03 21 2005.... Any way to get those spaces gone? This should finally do it. An error will be noted during execution, but can be ignored. I also changed the second occurance of %mm% to %min%.

@echo off
For /f "tokens=1-7 delims=:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (
For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (
set dow=%%i
set %%a=%%j
set %%b=%%k
set %%c=%%l
set hh=%%m
set min=%%n
set /a ss=%%o:~2
)
)

for /f "tokens=1-2 delims=." %%w in ('dir /b *.ecb') do (
ren %%w.%%x %%w%mm%%dd%%yy%%hh%%min%%ss%.%%x
)


Are you sure you don't want to switch to WinScript.

Good Luck. Quote
...Are you sure you don't want to switch to WinScript. ...


What kind of challenge would that be?
[sigh]


Discussion

No Comment Found