Help with Batch script.

Come up with a useful post-processing script? Share it here!
Ralph_Wiggum
Newbie
Newbie
Posts: 11
Joined: September 11th, 2012, 12:02 pm

Help with Batch script.

Post 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! :)
User avatar
sander
Release Testers
Release Testers
Posts: 8830
Joined: January 22nd, 2008, 2:22 pm

Re: Help with Batch script.

Post 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.
Ralph_Wiggum
Newbie
Newbie
Posts: 11
Joined: September 11th, 2012, 12:02 pm

Re: Help with Batch script.

Post by Ralph_Wiggum »

Sorry, for got to add that! I'm on WIN 7 :)

Ok, so ehm... how do I do that? :P
User avatar
sander
Release Testers
Release Testers
Posts: 8830
Joined: January 22nd, 2008, 2:22 pm

Re: Help with Batch script.

Post by sander »

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

Re: Help with Batch script.

Post by shypike »

sander wrote:See http://wiki.sabnzbd.org/user-scripts ... so "CD %1"
No, it's:
cd "%1"
User avatar
sander
Release Testers
Release Testers
Posts: 8830
Joined: January 22nd, 2008, 2:22 pm

Re: Help with Batch script.

Post by sander »

shypike wrote:
sander wrote:See http://wiki.sabnzbd.org/user-scripts ... so "CD %1"
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.
Ralph_Wiggum
Newbie
Newbie
Posts: 11
Joined: September 11th, 2012, 12:02 pm

Re: Help with Batch script.

Post 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

Code: Select all

cd "%1"
beneath

Code: Select all

echo off
in my script and I'm all set? :-S
User avatar
sander
Release Testers
Release Testers
Posts: 8830
Joined: January 22nd, 2008, 2:22 pm

Re: Help with Batch script.

Post by sander »

Ralph_Wiggum wrote: So, i just add

Code: Select all

cd "%1"
beneath

Code: Select all

echo off
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.
Ralph_Wiggum
Newbie
Newbie
Posts: 11
Joined: September 11th, 2012, 12:02 pm

Re: Help with Batch script.

Post 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 :P 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!
User avatar
sander
Release Testers
Release Testers
Posts: 8830
Joined: January 22nd, 2008, 2:22 pm

Re: Help with Batch script.

Post 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 :P 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"
Ralph_Wiggum
Newbie
Newbie
Posts: 11
Joined: September 11th, 2012, 12:02 pm

Re: Help with Batch script.

Post 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 ???
User avatar
sander
Release Testers
Release Testers
Posts: 8830
Joined: January 22nd, 2008, 2:22 pm

Re: Help with Batch script.

Post 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?
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Help with Batch script.

Post by shypike »

cd /d c:\my\full\path
Ralph_Wiggum
Newbie
Newbie
Posts: 11
Joined: September 11th, 2012, 12:02 pm

Re: Help with Batch script.

Post 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 :/
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Help with Batch script.

Post 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")
Post Reply