(req) File Rename Script (windows)

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

(req) File Rename Script (windows)

Postby themugger » December 1st, 2008, 1:42 pm

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. :)
themugger
Release Testers
Release Testers
 
Posts: 30
Joined: June 11th, 2008, 11:44 am

Re: (req) File Rename Script (windows)

Postby doubledrat » December 15th, 2008, 5:54 pm

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


doubledrat
Release Testers
Release Testers
 
Posts: 227
Joined: February 20th, 2008, 4:16 pm

Re: (req) File Rename Script (windows)

Postby shypike » December 16th, 2008, 7:35 am

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/articleid/77004/jsi-tip-5700-frequently-asked-questions-regarding-the-windows-2000-command-processor.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, 7:45 am, edited 1 time in total.
User avatar
shypike
Administrator
Administrator
 
Posts: 16548
Joined: January 18th, 2008, 1:49 pm

Re: (req) File Rename Script (windows)

Postby themugger » December 16th, 2008, 11:03 am

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

   

themugger
Release Testers
Release Testers
 
Posts: 30
Joined: June 11th, 2008, 11:44 am

Re: (req) File Rename Script (windows)

Postby Camelot » December 16th, 2008, 11:38 am

distr
Last edited by Camelot on December 17th, 2008, 5:22 am, edited 1 time in total.
Camelot
Jr. Member
Jr. Member
 
Posts: 64
Joined: August 18th, 2008, 7:23 am

Re: (req) File Rename Script (windows)

Postby doubledrat » December 16th, 2008, 5:44 pm

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
doubledrat
Release Testers
Release Testers
 
Posts: 227
Joined: February 20th, 2008, 4:16 pm

Re: (req) File Rename Script (windows)

Postby themugger » December 17th, 2008, 4:23 am

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
themugger
Release Testers
Release Testers
 
Posts: 30
Joined: June 11th, 2008, 11:44 am

Re: (req) File Rename Script (windows)

Postby adr3nal1n » December 18th, 2008, 7:56 am

Or you could just do this...

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

(Repeat as necessary for whatever file type)
adr3nal1n
Newbie
Newbie
 
Posts: 6
Joined: December 18th, 2008, 7:54 am


Return to Post-Processing Scripts