Page 1 of 2
Help with Batch script.
Posted: September 11th, 2012, 12:08 pm
by Ralph_Wiggum
Hello everyone!
I was wondering if anyone can help me with a batch script?
I can't figure out how I can get my script to do what I want in the folder I just downloaded. If it's done before or after moving from incomplete doesn't matter.
My scripting skills isn't much to brag about. I got a lot of help from google and some people on another site. I tried the manual here but didn't understand much unfortunately!
Here is my script, if it helps:
Code: Select all
echo off
IF EXIST *sample* (mkdir Sample && move *sample* "Sample") ELSE exit
IF EXIST *subs* (mkdir Subs && move *subs* "Subs") ELSE exit
Any help is much appreciated. Thanks in advance!

Re: Help with Batch script.
Posted: September 11th, 2012, 12:34 pm
by sander
For which operating system is this? Windows?
I don't use Windows, but my first thought: you have to CD the the download directory. The download directory is probably in one of the %1, %2, ... parameters.
Re: Help with Batch script.
Posted: September 11th, 2012, 12:54 pm
by Ralph_Wiggum
Sorry, for got to add that! I'm on WIN 7
Ok, so ehm... how do I do that?

Re: Help with Batch script.
Posted: September 11th, 2012, 2:02 pm
by sander
Re: Help with Batch script.
Posted: September 11th, 2012, 2:44 pm
by shypike
Re: Help with Batch script.
Posted: September 11th, 2012, 2:58 pm
by sander
shypike wrote:
No, it's:
cd "%1"
Ah ... I love shell scripting. NOT.
I would vote for to do all SABnzbd pre/post processing scripting in Python: easier and cross-platform. The module shutil looks very useful.
Re: Help with Batch script.
Posted: September 12th, 2012, 9:46 am
by Ralph_Wiggum
I looked at the page you linked to before I posted, but seeing as I am very new to this; it didn't help me much
So, i just add
beneath
in my script and I'm all set? :-S
Re: Help with Batch script.
Posted: September 12th, 2012, 10:34 am
by sander
Ralph_Wiggum wrote:
So, i just add
beneath
in my script and I'm all set? :-S
As said: that was my first thought. :-)
But don't trust me; trust yourself and your computer. The beauty of a SAB pre/post processing script is that you can run it from the command line (without running SAB) to see if/how it works. So make some directory, put some different files into it (among which a file blabla-sample-333.avi), and run the script on that directory (so : scriptblabla.bat "C:\blabla\mytestmoviedir\" ). Then inspect the results.
Interesting point to check if you really want to test thoroughly: what happens if there is already a subdirectory "blabla-sample-xyz", and you run the script on the parent directory ... the script will try to move the subdirectory, won't it? If so, what happens ...
As said: I have no Windows. So please test and develop yourself. You can always ask for directions and tips here.
Re: Help with Batch script.
Posted: September 12th, 2012, 11:49 am
by Ralph_Wiggum
I tried to just add cd "%1" at the top, but for some reason it made a Sample folder and moved a file in the Sab installation directory

So guess that didn't work
The script runs great when I do it manually with the script in the folder I want sorted. If I try it in a folder that's already sorted it creates a Sample folder within the Sample folder and moves it there. But that's not a big problem because new DLs will not be sorted. Guess I'm gonna just have to keep trying! Thanks for your input mate!

Really appreciate it!
Re: Help with Batch script.
Posted: September 12th, 2012, 11:53 am
by sander
Ralph_Wiggum wrote:I tried to just add cd "%1" at the top, but for some reason it made a Sample folder and moved a file in the Sab installation directory

So guess that didn't work
But did you run the script with the goal directory as parameter? So
Code: Select all
yourscript.bat "C:\blabla\testidr"
Re: Help with Batch script.
Posted: September 12th, 2012, 1:45 pm
by Ralph_Wiggum
sander wrote:
But did you run the script with the goal directory as parameter? So
Code: Select all
yourscript.bat "C:\blabla\testidr"
Ehm... don't think so. God, I feel so dumb. I just ran the script is it is. I copied it into the folder I wanted sorted and ran it there. That's about it.
The script is in my complete folder when Sab tries to use it. And I just added cd "%1" under echo off in the script in my first post

Re: Help with Batch script.
Posted: September 12th, 2012, 2:41 pm
by sander
Oh, wait ... Windows' CD only works for "\adfasdf\asdfasdf\", not for "C:\adsfasdf\asdfasdf\".
Ouch.
Isn't there an existing script that handles this specific CD problem?
Re: Help with Batch script.
Posted: September 12th, 2012, 3:03 pm
by shypike
cd /d c:\my\full\path
Re: Help with Batch script.
Posted: September 17th, 2012, 12:06 pm
by Ralph_Wiggum
I'm sorry for being a moron, but if you could just copy/paste what I have in the first post and add what is needed for the script to run in the downloaded folder?
All my complete stuff are on D:\Downloads (so the downloaded folder within there)
Again, I'm sorry for being so helpless, but I just can't figure it out. It's my first script :/
Re: Help with Batch script.
Posted: September 17th, 2012, 12:11 pm
by shypike
Code: Select all
echo off
cd /d "%1"
IF EXIST *sample* (mkdir Sample && move *sample* "Sample")
IF EXIST *subs* (mkdir Subs && move *subs* "Subs")