Adding the date as "YYYY-MM-DD - " to the extracted folder

Come up with a useful post-processing script? Share it here!

Adding the date as "YYYY-MM-DD - " to the extracted folder

Postby Bozzy » April 1st, 2012, 4:40 pm

All,

Just a quick windows bat file for adding the date as "YYYY-MM-DD - " to the start of the extracted folder name;

Code: Select all
@echo off
cd "%1"
set name="%3"
@For /F "tokens=1,2,3 delims=/ " %%A in ('Date /t') do @(
Set Day=%%A
Set Month=%%B
Set Year=%%C
Set All=%%C-%%B-%%A
)
ren "%1" "%All% - %name%"
Bozzy
Newbie
Newbie
 
Posts: 10
Joined: March 31st, 2012, 8:57 am

Re: Adding the date as "YYYY-MM-DD - " to the extracted fold

Postby Bozzy » April 16th, 2012, 4:43 pm

A little code cleanup...

Code: Select all
@echo off
cd %1
set name=%3
set name=%name:"=%

echo %DATE% %TIME%
for /F "tokens=1-3 delims=/" %%a in ("%DATE%") do set DAY=%%a& set MTH=%%b& set YR=%%c
for /F "tokens=1-3 delims=:." %%a in ("%TIME%") do set HR=%%a& set MIN=%%b& set SEC=%%c
if "%HR:~0,1%"==" " set HR=0%HR:~1,1%
set MYDATE=%YR%%MTH%%DAY%-%HR%%MIN%%SEC%
set NEWNAME=%MYDATE%_%3

ren %1 %NEWNAME%
Bozzy
Newbie
Newbie
 
Posts: 10
Joined: March 31st, 2012, 8:57 am

Re: Adding the date as "YYYY-MM-DD - " to the extracted fold

Postby PFTKev » April 21st, 2012, 9:20 am

I love the idea of this script, however, I've tried both versions. I'm getting the following error: The syntax of the command is incorrect. Is there anything else you can think of that I might need to change?
PFTKev
Newbie
Newbie
 
Posts: 1
Joined: April 21st, 2012, 8:56 am

Re: Adding the date as "YYYY-MM-DD - " to the extracted fold

Postby Bozzy » March 25th, 2013, 10:01 am

I was running the code with echo on to try and see what was wrong and found it was adding a space instead of a 0 when it was midnight...also added a ping in to create a 2 second pause in case there was permission locking.

Code: Select all
cd "%1"
set name="%3"
set name=%name:"=%

echo %DATE% %TIME%
for /F "tokens=1-3 delims=/" %%a in ("%DATE%") do set DAY=%%a& set MTH=%%b& set YR=%%c
for /F "tokens=1-3 delims=:." %%a in ("%TIME%") do set HR=%%a& set MIN=%%b& set SEC=%%c
IF "%HR:~0,1%" == " " SET HR=0%HR:~1,1%
set MYDATE=%YR%%MTH%%DAY%-%HR%%MIN%%SEC%
set NEWNAME=%MYDATE%_%3

ping 127.0.0.1 -n 2

rename %1 %NEWNAME%



This should work now it's tweaked.
Bozzy
Newbie
Newbie
 
Posts: 10
Joined: March 31st, 2012, 8:57 am


Return to Post-Processing Scripts