Add Date to Folders Name

February 24, 2010 at 08:04:28
Specs: Windows XP
How can I add the current Date to the end of all Folders using batch file or VB script?

Hello
Today
Yesterday
Tomorrow

Hello - 2-24-2010
Today - 2-24-2010
Yesterday - 2-24-2010
Tomorrow - 2-24-2010

Thanks


See More: Add Date to Folders Name

Report •

#1
February 24, 2010 at 08:35:38
here's one way:
@echo off & setlocal
copy %0.bat nul >nul
for /f %%a "skip=4" %%a in ('dir %0.bat /t:a') do set dt=%%a & goto :aa
:aa
set dt=%dt:/=-%
for /f "tokens=*" %%a in ('dir /b /ad *.*') do (
:: just putting echo here, replace when ready
echo ren "%%a" "%%a%dt%"
)

Report •

#2
February 24, 2010 at 08:55:57
Ok I'm lost! 1st i'm assuming this is a batch file! here's what I did, and it's not working.

@echo off & setlocal
copy %0.bat nul >nul
for /f %%a "skip=10" %%a in ('dir %0.bat /t:a') do set dt=%%a & goto :aa
:aa
set dt=%dt:/=-%
for /f "tokens=*" %%a in ('dir /b /ad *.*') do (:: echo ren "%%a" %%a%dt%")
pause


Report •

#3
February 24, 2010 at 09:00:36
sorry, i had the "skip" wrong, see resp #1 (edited)
supposed to be "skip=4"

Report •

Related Solutions

#4
February 24, 2010 at 09:11:11
Still no good, I named the batch file %0.bat and 0.bat
NO GOOD

@echo off & setlocal
copy %0.bat nul >nul
for /f %%a "skip=4" %%a in ('dir %0.bat /t:a') do set dt=%%a & goto :aa
:aa
set dt=%dt:/=-%
for /f "tokens=*" %%a in ('dir /b /ad *.*') do (:: echo ren "%%a" "%%a%dt%")
pause


Report •

#5
February 24, 2010 at 09:31:22
just name the batch file something normal: f.bat
%0 is intended to pick up the name of the batchfile.
you could substitute any existing filename.
other than that, it worked over here.

Report •

#6
February 24, 2010 at 09:41:05
OK here what I have

C:\temp>0.bat


@echo off & setlocal
copy %0.bat nul >nul
for /f %%a "skip=4" %%a in ('dir %0.bat /t:a') do set dt=%%a & goto :aa
:aa
set dt=%dt:/=-%
for /f "tokens=*" %%a in ('dir /b /ad *.*') do (:: echo ren "%%a" "%%a%dt%")


when I run the batch file I get this..

C:\temp>0.bat
"skip=4" was unexpected at this time.


Report •

#7
February 24, 2010 at 09:49:18
Oh! i'm sorry! my eyes went right past the flaw, this line was wrong:
for /f %%a "skip=4" %%a in ('dir %0.bat /t:a') do set dt=%%a & goto :aa

make it:
for /f "skip=4" %%a in ('dir %0.bat /t:a') do set dt=%%a & goto :aa

(remove the very first "%%a")
my bad entirely!


Report •

#8
February 24, 2010 at 10:52:20
Could you please verify the changes I made are correct? Thanks

c:\temp>0.bat

@echo off & setlocal
copy %0.bat nul >nul
for /f "skip=4" %%a in ('dir %0.bat /t:a') do set dt=%%a & goto :aa
set dt=%dt:/=-%
for /f "tokens=*" %%a in ('dir /b /ad *.*') do (:: echo ren "%%a" "%%a%dt%")


C:\temp>0.bat
File Not Found
do was unexpected at this time.


Report •

#9
February 24, 2010 at 12:18:42
you can't use colons next to parentheses, it makes errors.
I'll just repost the whole shebang:
@echo off & setlocal
copy %0.bat nul >nul
for /f "skip=4" %%a in ('dir %0.bat /t:a') do set dt=%%a & goto :aa
:aa
set dt=%dt:/=-%
for /f "tokens=*" %%a in ('dir /b /ad *.*') do (
echo ren "%%a" "%%a%dt%"
)

:: ---- end of script
the echo does not need to be comm'd out, since it doesn't do any "destructive" operation - just displays.
when you want to activate the script, take echo off the line so it looks like:
ren "%%a" "%%a%dt%"

and be sure to leave the :aa in there! it is a label.


Report •

#10
March 2, 2010 at 10:53:25
We’ll I didn’t have any successes making your script to work. So I change the order I went to the destination and run my batch file from there and it’s working fine this way. Thanks the your help anyway.

@echo off
FOR /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do set var=%%a-%%b-%%c
mkdir %var%
set srcDir=..\Point_A
set destDir=%var%
for /f "delims=" %%a in ('dir "%srcDir%" /s /b 2^>NUL') do copy "%%a" "%destDir%"


Report •

#11
March 3, 2010 at 14:42:27
Got something working, but you also need "getdt" to make it work. Send me a PM with your email, and then you can run this:


@echo on

call getdt

for /D %%f in (*) do echo rename "%%f" "%%f - %dt_day%-%dt_month%-%dt_year%"


Report •

Ask Question