Hi all,
I would like to run a simple scrip that renames the folder that's automatically extracted to have the date in front of it, ie, to go from
'blah blah extrated folder' ---> ''2012-03-31 - blah blah extrated folder'
Using the date format of YYYY-MM-DD
Could anyone help me on where to start?
Help on a simple script to rename folders
Forum rules
Help us help you:
Help us help you:
- Are you using the latest stable version of SABnzbd? Downloads page.
- Tell us what system you run SABnzbd on.
- Adhere to the forum rules.
- Do you experience problems during downloading?
Check your connection in Status and Interface settings window.
Use Test Server in Config > Servers.
We will probably ask you to do a test using only basic settings. - Do you experience problems during repair or unpacking?
Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Re: Help on a simple script to rename folders
A good start would be to tell on which operating system you want to run it.
Re: Help on a simple script to rename folders
Yes, it would!
Im on Windows 7 x64
Im on Windows 7 x64
Re: Help on a simple script to rename folders
Code: Select all
@echo off
cd %1
set name=%3
set name=%name:"=%
set stamp=%date:~3%
set dd=%stamp:~,2%
set mm=%stamp:~3,2%
set yy=%stamp:~8,2%
ren "%name%" "20%yy%-%mm%-%dd% - %name%"
If not, then you must change the order in the last line.
Re: Help on a simple script to rename folders
Many thanks for that, I didn't think it was as simple as an MSDOS bat file!
You set me on a path to remember my old programming days, so I had ago myself too......this was my attempt, both work well.
You set me on a path to remember my old programming days, so I had ago myself too......this was my attempt, both work well.
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%"Re: Help on a simple script to rename folders
I think you need these two lines:
set name=%3
set name=%name:"=%
They remove the surrounding quotes (") from the foldername, otherwise you will get commands like this:
ren "bla" "2012-04-02 - "bla"
set name=%3
set name=%name:"=%
They remove the surrounding quotes (") from the foldername, otherwise you will get commands like this:
ren "bla" "2012-04-02 - "bla"
Re: Help on a simple script to rename folders
Cheers again for the help.
Ended up changing it a bit and taking your advice
Ended up changing it a bit and taking your advice
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%Re: Help on a simple script to rename folders
Well.......
I never quite got this to work, so I may as well bump it.
It works on some folders, but not on others, and there doesn't seem to be any pattern as to why (ie similar non alpha-numeric characters)
I'm thinking maybe windows may be locking the folder for thumbnail generation or something similar. I know it's a bit vague, but does anyone have any advice?
I never quite got this to work, so I may as well bump it.
It works on some folders, but not on others, and there doesn't seem to be any pattern as to why (ie similar non alpha-numeric characters)
I'm thinking maybe windows may be locking the folder for thumbnail generation or something similar. I know it's a bit vague, but does anyone have any advice?
Re: Help on a simple script to rename folders
On WIndows, disable folder renaming in Config->Switches.
Re: Help on a simple script to rename folders
Unfortunately it already is Shypike.....
Re: Help on a simple script to rename folders
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.
This should work now it's tweaked.
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%

