Whats wrong with my batch script?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jkaberg
Posts: 3
Joined: 13 Jan 2013 02:18

Whats wrong with my batch script?

#1 Post by jkaberg » 13 Jan 2013 02:26

Tryd asking on another forum but no guru's there ;) Im actully quite new to batch scripting but thought I'd give this a try since its more comfortable like this

I got this script wich I use with an older verision of uTorrent (2.2.1), what I want the script to do is either extract or move depending on the files in the downloaded folder to another folder depending on which label the torrent got in uTorrent. I can append stuff like downloaded location and label like this > C:\unpack.bat %D %N %L

Where %D referes to download location, %N refers to the name of the torrent and %L refers to the label it got

But somehow my code dosnt work all that well, and since im quite green on this I was wondering if some jedi batch master could help me out :)

In short what I want my script to do

IF no label quit (to avoid anything but movies and tv series get extracted since these are the only ones that will have labels)
IF rar files extract them to location/labelname/torrentname
IF no rar files but movie files copy them to location/labelname/torrentname

Code: Select all

@ECHO OFF


rem C:\unpack.bat %D %N %L


SET ouputdir=D:\Downloaded\Torrents\complete\
SET winrarpath="C:\Program Files\WinRAR\WinRAR.exe"


SET input=%1
SET name=%2
SET label=%3
SET output=%outputdir%\%label%\%name%

IF %label%==() GOTO:EOF
IF EXIST %input%\*.rar GOTO extract
IF EXIST %input%\*.mkv GOTO copy
IF EXIST %input%\*.avi GOTO copy
IF EXIST %input%\*.mp4 GOTO copy
GOTO:EOF

:copy
IF NOT EXIST %outputdir%\%label% MKDIR %outputdir%\%label%
IF NOT EXIST %output% MKDIR %output%
xcopy %input%\*.* %output% /S /I /Y
GOTO:EOF

:extract
IF NOT EXIST %outputdir%\%label% MKDIR %outputdir%\%label%
IF NOT EXIST %output% MKDIR %output%
%winrarpath% x -ilog %input%\*.rar *.* %output%
GOTO:EOF


Btw is it possible to match several .rar types with a regexp (like forexample .rar/r01/.r01/.part01 and so forth?)

Thanks for any help given, much appreciated

PS: Optimizations tips are highly welcome :P

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Whats wrong with my batch script?

#2 Post by foxidrive » 13 Jan 2013 02:45

jkaberg wrote:Tryd asking on another forum but no guru's there ;) Im actully quite new to batch scripting but thought I'd give this a try since its more comfortable like this

I got this script wich I use with an older verision of uTorrent (2.2.1), what I want the script to do is either extract or move depending on the files in the downloaded folder to another folder depending on which label the torrent got in uTorrent. I can append stuff like downloaded location and label like this > C:\unpack.bat %D %N %L

Where %D referes to download location, %N refers to the name of the torrent and %L refers to the label it got


Does Utorrent launch this batch file and supply the arguments?
Can you provide some sample command lines?

jkaberg
Posts: 3
Joined: 13 Jan 2013 02:18

Re: Whats wrong with my batch script?

#3 Post by jkaberg » 13 Jan 2013 02:52

foxidrive wrote:
jkaberg wrote:Tryd asking on another forum but no guru's there ;) Im actully quite new to batch scripting but thought I'd give this a try since its more comfortable like this

I got this script wich I use with an older verision of uTorrent (2.2.1), what I want the script to do is either extract or move depending on the files in the downloaded folder to another folder depending on which label the torrent got in uTorrent. I can append stuff like downloaded location and label like this > C:\unpack.bat %D %N %L

Where %D referes to download location, %N refers to the name of the torrent and %L refers to the label it got


Does Utorrent launch this batch file and supply the arguments?
Can you provide some sample command lines?


Yeah it does

Example lines would be something along with

unpack.bat F:\Downloaded\Torrents\seeded\Cloud.Atlas.2012.1080p.Bluray.X264-HDT Cloud.Atlas.2012.1080p.Bluray.X264-HDT movies

or

unpack.bat F:\Downloaded\Torrents\seeded\Sirkus.Northug.S01E01.NORWEGiAN.720p.HDTV.x264-TvNORGE Sirkus.Northug.S01E01.NORWEGiAN.720p.HDTV.x264-TvNORGE tvseries

I hope there isnt any anti-fileshareing activists here :P :)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Whats wrong with my batch script?

#4 Post by foxidrive » 13 Jan 2013 02:53

Are there no double quotes in there?

jkaberg
Posts: 3
Joined: 13 Jan 2013 02:18

Re: Whats wrong with my batch script?

#5 Post by jkaberg » 13 Jan 2013 02:56

Yeah, sorry my bad. Wrote my reply in a hurry! They're wrapped in double quotes eg

unpack.bat "F:\Downloaded\Torrents\seeded\Cloud.Atlas.2012.1080p.Bluray.X264-HDT" "Cloud.Atlas.2012.1080p.Bluray.X264-HDT" "movies"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Whats wrong with my batch script?

#6 Post by foxidrive » 13 Jan 2013 08:01

This is untested but it should handle long filenames and pathnames.

Code: Select all

@ECHO OFF

rem C:\unpack.bat %D %N %L

SET "outputdir=D:\Downloaded\Torrents\complete\"
SET "winrarpath=C:\Program Files\WinRAR\WinRAR.exe"

SET "input=%~1"
SET "name=%~2"
SET "label=%~3"
SET "output=%outputdir%\%label%\%name%"

IF "%label%"=="" GOTO:EOF

IF exist "%input%\*.rar (
MKDIR "%outputdir%\%label%" 2>nul
MKDIR "%output%" 2>nul
"%winrarpath%" x -ilog "%input%\*.rar" *.* "%output%"
)

IF exist "%input%\*.mkv" (
MKDIR "%outputdir%\%label%" 2>nul
xcopy "%input%\*.mkv" "%output%\" /S /I /Y
)

IF exist "%input%\*.avi" (
MKDIR "%outputdir%\%label%" 2>nul
xcopy "%input%\*.avi" "%output%\" /S /I /Y
)

IF exist "%input%\*.mp4" (
MKDIR "%outputdir%\%label%" 2>nul
xcopy "%input%\*.mp4" "%output%\" /S /I /Y
)

goto :EOF

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Whats wrong with my batch script?

#7 Post by Squashman » 13 Jan 2013 10:13

jkaberg wrote:I hope there isnt any anti-fileshareing activists here :P :)

Yes but we have no defined rule on not helping with it. I am sure if the RIAA or MPAA come knocking on our door with a subponea asking for your IP address I am sure we will have to comply with the request.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Whats wrong with my batch script?

#8 Post by Ed Dyreen » 13 Jan 2013 10:55

'
Torrent files often consist of unicode characters, you will find batch can't handle unicode eg:
renaming moving files. VB-/J-script however does handle unicode and is much easier and robust language.

DosTips is hosted from US and bound to US laws and international treaties.
In US filesharing technology is legal, the files you share may not.
Anti-fileshareing activism is off-topic and will be removed.

Better avoid those discussion are off-topic too.
ed

Post Reply