Page 1 of 1
(req) File Rename Script (windows)
Posted: December 1st, 2008, 12:42 pm
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.
Re: (req) File Rename Script (windows)
Posted: December 15th, 2008, 4:54 pm
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
Re: (req) File Rename Script (windows)
Posted: December 16th, 2008, 6:35 am
by shypike
Removing quotes is rather easy to do in CMD itself.
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.)
Re: (req) File Rename Script (windows)
Posted: December 16th, 2008, 10:03 am
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
Re: (req) File Rename Script (windows)
Posted: December 16th, 2008, 10:38 am
by Camelot
distr
Re: (req) File Rename Script (windows)
Posted: December 16th, 2008, 4:44 pm
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
Re: (req) File Rename Script (windows)
Posted: December 17th, 2008, 3:23 am
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
Re: (req) File Rename Script (windows)
Posted: December 18th, 2008, 6:56 am
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)