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

Come up with a useful post-processing script? Share it here!
Post Reply
Bozzy
Newbie
Newbie
Posts: 10
Joined: March 31st, 2012, 7:57 am

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

Post by Bozzy »

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, 7:57 am

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

Post by Bozzy »

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%
PFTKev
Newbie
Newbie
Posts: 1
Joined: April 21st, 2012, 7:56 am

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

Post by PFTKev »

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?
Bozzy
Newbie
Newbie
Posts: 10
Joined: March 31st, 2012, 7:57 am

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

Post by Bozzy »

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.
Cogsworth
Newbie
Newbie
Posts: 8
Joined: April 10th, 2014, 3:20 am

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

Post by Cogsworth »

I have been trying to get this functionality as well but I am clueless about scripts...I've tried to run this one and I also get the "syntax of the command is incorrect" error...any ideas on how I can get it to work? Thanks!
Cogsworth
Newbie
Newbie
Posts: 8
Joined: April 10th, 2014, 3:20 am

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

Post by Cogsworth »

After reading, learning and tweaking I finally figured out I was getting the syntax error because %DATE% returned a different format on my system "Thu 04/24/2014" which resulted in the DAY being read as Thu 04 and consequently the rename command was trying to specify a target name with a space in it, minus the requisite quotation marks. I did some tinkering and came up with the following script which is working perfectly and renames the extracted folder exactly the same as Newsbin does: DD-MM-YYYY HHMM - FILE NAME. Thanks for the original script!

Code: Select all

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

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

ren %1 "%NEWNAME%"
Post Reply