[Windows-Solved]Copying files to two folders+strip "samples"

Come up with a useful post-processing script? Share it here!
Post Reply
ehsuds
Newbie
Newbie
Posts: 2
Joined: December 5th, 2012, 9:22 pm

[Windows-Solved]Copying files to two folders+strip "samples"

Post by ehsuds »

I'm trying to get SABNZBD to run a batch file that I wrote every time a download in category "TV" is completed and unpacked that will copy the unpacked video file only to two separate folders, rename the original file, and also delete the "sample" video files that are supposedly used to test quality before copying all of the video files.

I'm having a bit of difficulty getting my script to run, any help appreciated, script attached below

EDIT: SNIP, SEE SECOND POST FOR SOLUTION
Last edited by ehsuds on December 6th, 2012, 3:20 am, edited 1 time in total.
ehsuds
Newbie
Newbie
Posts: 2
Joined: December 5th, 2012, 9:22 pm

Re: [Windows] Help getting .bat to run.

Post by ehsuds »

OK, I got it working, hopefully this is helpful for others who are using windows and want to copy files to two separate locations.

It's currently setup for video files, but by changing extensions (it's a configurable option) it will handle any other type of file. For audio files, I'd recommend setting prune to no.

What it does:
*Optionally deletes any file of selected extensions less than a size you choose. Typically there are "sample files", I never want them so it deletes them automatically. I have it set to ~40 MB, but you can change it to anythign you want, this size is defined in bytes
*Copies Any remaining files of selected extensions to the fist destination
*Optionally Copies those same files of selected extensions to a second destination if specified
*Renames the original folder, adding "MOVED-" to the front of the name. This is so you know it was processed, but leaving it there for manual deletion in case a move didn't go as planned. For example if the folder was named "Friends S01E01", it would be renamed to "MOVED-Friends S01E01"


How I set it up:
*Place both fc2.bat and sortTV.bat into the same root folder that all of your downloads go into (the same spot as Completed Download Folder under config->folders).
*Edit the last line of sortTV.bat so it copies to the paths you choose.
*In SABNZBD, goto config->folders, set your Post-Processing Scripts Folder to the same thing as your Completed Download Folder
*In SABNZBD, goto config->categories, set the script to sortTV.bat for the appropriate category
*Edit fc2.bat in the configuration area.



FILENAME: sortTV.bat

Code: Select all

@echo off
cd /d %1
cd ..
REM **** DONT CHANGE ANYTHING ABOVE THIS POINT*****

REM **** START CONFIGURATION HERE ************
REM **** CHANGE THE DESTINATION PATH and OPTIONALLY ADD A SECOND PATH, leave foldername as %3
REM **** Destinations can be network paths or local paths
REM  USAGE IS: fc2.bat [foldername] [destination1] [destination 2 optional]

fc2.bat %3 \\MEDIACENTER-PC\UnwatchedTV \\NAS\ArchivedTV



FILENAME: fc2.bat

Code: Select all

@echo off
REM **** Switches to folder,collapses subfolders into main unpack folder, 
REM **** optionally deleted undersized files, copies specified file formats to destination or destinations ***
REM **** Renames old data structure to "MOVED-"plus the orignial folder name.
REM **** USAGE IS: fc2 [foldername] [destination1] [destination 2 optional]


REM *********CONFIGURATION************

REM *** FILE EXTENSIONS TO COPY, SPACE BETWEEN DIFFERENT FILE TYPES ***
set ext=*.MKV *.WMV *.AVI *.MP4

REM ***** DELETE FILES OF COPY EXTENSIONS IF LESS THAN A CERTAIN SIZE, this is case sensitive (yes or no) and (size in bytes)****
REM ***** THe PRUNE EXTENSIONS ARE THE SAME AS THE FILE EXTENSIONS TO COPY, Prune enables/disables
set prune=yes
set prunesize=41240000

REM ****ADDITINAL FILE EXTENSIONS TO PRUNE, NO FILESIZE LIMIT****
REM ****prune2 = case sensitive (yes or no) to enable or disable deleting, SPACE BETWEEN DIFFERENT FILE TYPES
set prune2=yes
set prune2ext=*.SRR *.NZB *.SRS

REM *******END CONFIGURATION**************


REM *** GO TO UNPACKED FOLDER ***
cd %1

REM ***Collapse all subfolders into main unpack folder, overwrite duplicates***
for /r %%i in (*) do @move /y "%%i" "%%~nxi"

REM **** DELETES all Files of  ****
if "%prune2%" == "yes" (
for %%m in (%prune2ext%) do for /F "delims=" %%A in ('dir /b %%m') do del "%%~dpnxA"
)

REM ****Delete any Video less than ~40 MB to remove samples ****
if "%prune%" == "yes" (
for %%m in (%ext%) do for /F "delims=" %%A in ('dir /b %%m') do if %%~zA LEQ %prunesize% del "%%~dpnxA"
)

REM **** Copy Video Files to Destination folder *****
for %%x in (%ext%) do copy /y %%x %2

        REM ****Copy video files to second Destination if request exists****
   if NOT "%3" == "" (
   for %%x in (%ext%) do copy /y %%x %3
   )

REM ****Traverse back to primary directory, rename and append MOVED- to folder name for manual move verification before delete****
cd ..
ren %1 MOVED-%1
Post Reply