(req) File Rename Script (windows)

Come up with a useful post-processing script? Share it here!
Post Reply
themugger
Release Testers
Release Testers
Posts: 30
Joined: June 11th, 2008, 10:44 am

(req) File Rename Script (windows)

Post by themugger »

Hi All, i have had a good look through but cannot see anything similar to what im after. all i want to do is rename the movie file/s to the folder name after downloading. I have no scripting experience so was wondering if anyone had something already along these lines.

This is for Windows, thanks for any help with this. :)
doubledrat
Release Testers
Release Testers
Posts: 180
Joined: February 20th, 2008, 3:16 pm

Re: (req) File Rename Script (windows)

Post by doubledrat »

this is more difficult than it might seem, because sab only tells you the folder name.  Also, it wraps params  in "" which can cause grief.  SO this might look overly complex, but I believe it's necessary.  you also need to download the unix util (win version) sed 1.5, which as you can see I have put in c:\uutils

Code: Select all

call :remquot %3
set name=%newvar%

REM rename isos or bins

call :remquot %1
set dirname=%newvar%

for %%f in ("%dirname%\*.iso") do rename "%%f" "%name%.iso"
for %%f in ("%dirname%\*.bin") do rename "%%f" "%name%.bin"
for %%f in ("%dirname%\*.nrg") do rename "%%f" "%name%.nrg"
for %%f in ("%dirname%\*.img") do rename "%%f" "%name%.img"
for %%f in ("%dirname%\*.mdf") do rename "%%f" "%name%.mdf"

GOTO :EOF


:remquot
echo %1| c:\uutils\sed15.exe -e "s/^/set newvar\=/" -e "s/\"//g" > newvar.bat
call newvar.bat
del newvar.bat
GOTO :EOF


User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: (req) File Rename Script (windows)

Post by shypike »

Removing quotes is rather easy to do in CMD itself.

Code: Select all

set name=%1
set name=%name:"=%
For more info on this see:
http://windowsitpro.com/article/article ... essor.html

BTW, it's not possible for us to remove the quotes.
It's something deep down in the Windows libraries of the programming language (Python) we use.

(The problem does not occur on Linux/OSX, there you will never get quotes.)
Last edited by shypike on December 16th, 2008, 6:45 am, edited 1 time in total.
themugger
Release Testers
Release Testers
Posts: 30
Joined: June 11th, 2008, 10:44 am

Re: (req) File Rename Script (windows)

Post by themugger »

Thanks for your help in trying to write this script for me, unfortunetly (most probally me doing something totally wrong) it does not work for me - the error from this script is below...

Code: Select all

Beowulf_(2007)_(Trailer).log
    
c:\Program Files\SABnzbd>call :remquot Beowulf_(2007)_(Trailer) 

c:\Program Files\SABnzbd>echo Beowulf_(2007)_(Trailer)  | d:\downloads\scripts\sed15.exe -e "s/^/set newvar\=/" -e "s/\"//g" > newvar.bat 
sed: cannot open >

c:\Program Files\SABnzbd>call newvar.bat 
'newvar.bat' is not recognized as an internal or external command,
operable program or batch file.

c:\Program Files\SABnzbd>del newvar.bat 
Could Not Find c:\Program Files\SABnzbd\newvar.bat

c:\Program Files\SABnzbd>GOTO :EOF 

c:\Program Files\SABnzbd>set name= 

c:\Program Files\SABnzbd>REM rename isos or bins 

c:\Program Files\SABnzbd>call :remquot D:\shares\Downloads\Beowulf_(2007)_(Trailer) 

c:\Program Files\SABnzbd>echo D:\shares\Downloads\Beowulf_(2007)_(Trailer)  | d:\downloads\scripts\sed15.exe -e "s/^/set newvar\=/" -e "s/\"//g" > newvar.bat 
sed: cannot open >
The process tried to write to a nonexistent pipe.

c:\Program Files\SABnzbd>call newvar.bat 
'newvar.bat' is not recognized as an internal or external command,
operable program or batch file.

c:\Program Files\SABnzbd>del newvar.bat 
Could Not Find c:\Program Files\SABnzbd\newvar.bat

c:\Program Files\SABnzbd>GOTO :EOF 

c:\Program Files\SABnzbd>set dirname= 

c:\Program Files\SABnzbd>for %f in ("\*.iso") do rename "%f" ".iso" 

c:\Program Files\SABnzbd>for %f in ("\*.bin") do rename "%f" ".bin" 

c:\Program Files\SABnzbd>for %f in ("\*.nrg") do rename "%f" ".nrg" 

c:\Program Files\SABnzbd>for %f in ("\*.img") do rename "%f" ".img" 

c:\Program Files\SABnzbd>for %f in ("\*.mdf") do rename "%f" ".mdf" 

c:\Program Files\SABnzbd>for %f in ("\*.mov") do rename "%f" ".mov" 

c:\Program Files\SABnzbd>GOTO :EOF 

    

Camelot
Jr. Member
Jr. Member
Posts: 64
Joined: August 18th, 2008, 6:23 am

Re: (req) File Rename Script (windows)

Post by Camelot »

distr
Last edited by Camelot on December 17th, 2008, 4:22 am, edited 1 time in total.
doubledrat
Release Testers
Release Testers
Posts: 180
Joined: February 20th, 2008, 3:16 pm

Re: (req) File Rename Script (windows)

Post by doubledrat »

that is a neat trick with the quotes; cheers :)  I managed to completely overlook that feature!



so, themugger, replace

Code: Select all

call :remquot %1
set dirname=%newvar%
with

Code: Select all

set dirname=%1
set dirname=%dirname:"=%
and the same sort of thing for the name variable and you should be good to go
themugger
Release Testers
Release Testers
Posts: 30
Joined: June 11th, 2008, 10:44 am

Re: (req) File Rename Script (windows)

Post by themugger »

perfect, changed the script and all working now - thankyou. for any one else that would like to use this then below is the script

Code: Select all

set name=%3
set name=%name:"=%

REM rename isos or bins

set dirname=%1
set dirname=%dirname:"=%

for %%f in ("%dirname%\*.iso") do rename "%%f" "%name%.iso"
for %%f in ("%dirname%\*.bin") do rename "%%f" "%name%.bin"
for %%f in ("%dirname%\*.nrg") do rename "%%f" "%name%.nrg"
for %%f in ("%dirname%\*.img") do rename "%%f" "%name%.img"
for %%f in ("%dirname%\*.mdf") do rename "%%f" "%name%.mdf"
for %%f in ("%dirname%\*.mov") do rename "%%f" "%name%.mov"
for %%f in ("%dirname%\*.avi") do rename "%%f" "%name%.avi"

GOTO :EOF


:remquot
echo %1| "D:\downloads\scripts\sed15.exe" -e "s/^/set newvar\=/" -e "s/\"//g" > newvar.bat
Thanks again doubledrat
adr3nal1n
Newbie
Newbie
Posts: 6
Joined: December 18th, 2008, 6:54 am

Re: (req) File Rename Script (windows)

Post by adr3nal1n »

Or you could just do this...

cd /d %1
if exist *.iso ren *.iso %3.iso

(Repeat as necessary for whatever file type)
Post Reply