[Windows] Download Dir Cleaner

Come up with a useful post-processing script? Share it here!
eagle00789
Newbie
Newbie
Posts: 30
Joined: July 5th, 2008, 9:40 am

[Windows] Download Dir Cleaner

Post by eagle00789 »

The code below cleans the download dir from the following files: nzb, sfv, url and db

Code: Select all

@echo off
setlocal
set fcount=0
set nzbcount=0
set sfvcount=0
set urlcount=0
set dbcount=0
 
echo.
echo [Cleanup] Cleaning up download directory: %1
 
echo [Cleanup] Deleteing .nzb files
for /f %%V in ('dir %1*.nzb /b /s ^2^>NUL ^| find /v /c ""') do set/a nzbcount = %%V
if %nzbcount% GTR 0 del /s /q "%1"*.nzb > NUL 2>NUL
 
echo [Cleanup] Deleteing .sfv files
for /f %%V in ('dir %1*.sfv /b /s ^2^>NUL ^| find /v /c ""') do set/a sfvcount = %%V
if %sfvcount% GTR 0 del /s /q "%1"*.sfv > NUL 2>NUL
 
echo [Cleanup] Deleteing .url files
for /f %%V in ('dir %1*.url /b /s ^2^>NUL ^| find /v /c ""') do set/a urlcount = %%V
if %urlcount% GTR 0 del /s /q "%1"*.url > NUL 2>NUL
 
echo [Cleanup] Deleteing .db files
for /f %%V in ('dir %1*.db /b /s ^2^>NUL ^| find /v /c ""')  do set/a dbcount  = %%V
if %dbcount% GTR 0 del /s /q "%1"*.db > NUL 2>NUL
 
set/a fcount = %nzbcount% + %sfvcount% + %urlcount% + %dbcount%
 
echo [Cleanup] Deleted %fcount% files (%nzbcount% nzb, %sfvcount% sfv, %urlcount% url, %dbcount% db)
echo.
Last edited by eagle00789 on July 23rd, 2008, 11:38 am, edited 1 time in total.
eagle00789
Newbie
Newbie
Posts: 30
Joined: July 5th, 2008, 9:40 am

Re: [Windows] Download Dir Cleaner

Post by eagle00789 »

Small update to the script to make the output a bit more cleaner then before. Before, if a file was not found (like nzb for example) in the complete dir, then an error would show up saying "File not found". this version has that error removed (With help from EE)
DeXeS
Release Testers
Release Testers
Posts: 206
Joined: January 28th, 2008, 1:04 pm
Location: The Netherlands

Re: [Windows] Download Dir Cleaner

Post by DeXeS »

Nice!

Does this script run a cleanup before or after the parring and unpacking?
eagle00789
Newbie
Newbie
Posts: 30
Joined: July 5th, 2008, 9:40 am

Re: [Windows] Download Dir Cleaner

Post by eagle00789 »

pair of dimes wrote:
DeXeS wrote: Nice!

Does this script run a cleanup before or after the parring and unpacking?
I'm sure after, as that is when all post-processing scripts are executed.
Indeed After the parring, unpacking and moving to the download-dir
EvilSIN
Newbie
Newbie
Posts: 3
Joined: August 22nd, 2008, 8:45 pm

Re: [Windows] Download Dir Cleaner

Post by EvilSIN »

thnx for the script
deepblue
Newbie
Newbie
Posts: 21
Joined: August 24th, 2008, 3:28 pm

Re: [Windows] Download Dir Cleaner

Post by deepblue »

Hi Guys,

I'm trying to get this to work on 0.4.2 (Win32), and Sabnzbd is running it, but it doesn't appear to be removing the files. Here's the output:

---------------------

SABnzbd has downloaded 'XXXX'.

Finished at 2008-08-24 15:51:06
Downloaded 366.4 MB

Results of the job:

Stage Download
  [Avg-Speed] 1371kB/s
  [Time-Taken] 4 minutes 33 seconds
Stage Par2
  [PAR-INFO] XXXXX => Verified in 19.1s, all files correct
  [DEL-INFO] XXXXX => Deleted 3 file(s)
Stage Unrar
  [DEL-INFO] XXXXX=> Deleted 25 file(s)
  [RAR-INFO] XXXXX => Unpacked 1 file(s) in 23.8s
Stage UserScript
  [USER-SCRIPT] => Running user script E:\NZB\SAB\scripts\cleanup.cmd

External processing by E:\NZB\SAB\scripts\cleanup.cmd:

[Cleanup] Cleaning up download directory: "E:\XBMC\Video\TV\XXXXX"
[Cleanup] Deleteing .nzb files
[Cleanup] Deleteing .sfv files
[Cleanup] Deleteing .url files
[Cleanup] Deleteing .db files
[Cleanup] Deleted 0 files (0 nzb, 0 sfv, 0 url, 0 db)

---------------------

I've checked the folder it is referencing, and there is a .nzb and .sfv file still sitting there. Any ideas? Can I adjust this to remove .nfo files just by tweaking the extensions in the code?

Thanks.
cydine
Newbie
Newbie
Posts: 4
Joined: August 24th, 2008, 4:22 pm

Re: [Windows] Download Dir Cleaner

Post by cydine »

Seems to be missing a couple vital backslashes.

Here's a slightly modded version that works for me. Removes nfo, nzb, sfv, idx, sub.

Code: Select all

@echo off
setlocal
set fcount=0
set nzbcount=0
set sfvcount=0
set nfocount=0
set subcount=0
set idxcount=0
 
echo.
echo [Cleanup] Cleaning up download directory: %1
 
echo [Cleanup] Deleting .nzb files
for /f %%V in ('dir %1\*.nzb /b /s ^2^>NUL ^| find /v /c ""') do set/a nzbcount = %%V
if %nzbcount% GTR 0 del /s /q %1\*.nzb > NUL 2>NUL
 
echo [Cleanup] Deleting .sfv files
for /f %%V in ('dir %1\*.sfv /b /s ^2^>NUL ^| find /v /c ""') do set/a sfvcount = %%V
if %sfvcount% GTR 0 del /s /q %1\*.sfv > NUL 2>NUL

echo [Cleanup] Deleting .nfo files
for /f %%V in ('dir %1\*.nfo /b /s ^2^>NUL ^| find /v /c ""') do set/a nfocount = %%V
if %nfocount% GTR 0 del /s /q %1\*.nfo > NUL 2>NUL

echo [Cleanup] Deleting .sub files
for /f %%V in ('dir %1\*.sub /b /s ^2^>NUL ^| find /v /c ""') do set/a subcount = %%V
if %subcount% GTR 0 del /s /q %1\*.sub > NUL 2>NUL

echo [Cleanup] Deleting .idx files
for /f %%V in ('dir %1\*.idx /b /s ^2^>NUL ^| find /v /c ""') do set/a idxcount = %%V
if %idxcount% GTR 0 del /s /q %1\*.idx > NUL 2>NUL
 
set/a fcount = %nzbcount% + %sfvcount% + %nfocount% + %subcount% + %idxcount%
 
echo [Cleanup] Deleted %fcount% files (%nfocount% nfo, %nzbcount% nzb, %sfvcount% sfv, %subcount% sub, %idxcount% idx)
echo.
eagle00789
Newbie
Newbie
Posts: 30
Joined: July 5th, 2008, 9:40 am

Re: [Windows] Download Dir Cleaner

Post by eagle00789 »

here is the updated version without the NFO file deletion as some downloads have some valuable info in the nfo-file...

Code: Select all

@echo off
setlocal
set fcount=0
set nzbcount=0
set sfvcount=0
set subcount=0
set idxcount=0
set urlcount=0
set dbcount=0
 
echo.
echo [Cleanup] Cleaning up download directory: %1
 
echo [Cleanup] Deleting .nzb files
for /f %%V in ('dir %1\*.nzb /b /s ^2^>NUL ^| find /v /c ""') do set/a nzbcount = %%V
if %nzbcount% GTR 0 del /s /q %1\*.nzb > NUL 2>NUL
 
echo [Cleanup] Deleting .sfv files
for /f %%V in ('dir %1\*.sfv /b /s ^2^>NUL ^| find /v /c ""') do set/a sfvcount = %%V
if %sfvcount% GTR 0 del /s /q %1\*.sfv > NUL 2>NUL

echo [Cleanup] Deleting .sub files
for /f %%V in ('dir %1\*.sub /b /s ^2^>NUL ^| find /v /c ""') do set/a subcount = %%V
if %subcount% GTR 0 del /s /q %1\*.sub > NUL 2>NUL

echo [Cleanup] Deleting .idx files
for /f %%V in ('dir %1\*.idx /b /s ^2^>NUL ^| find /v /c ""') do set/a idxcount = %%V
if %idxcount% GTR 0 del /s /q %1\*.idx > NUL 2>NUL
 
echo [Cleanup] Deleting .url files
for /f %%V in ('dir %1\*.url /b /s ^2^>NUL ^| find /v /c ""') do set/a urlcount = %%V
if %urlcount% GTR 0 del /s /q %1\*.url > NUL 2>NUL

echo [Cleanup] Deleting .db files
for /f %%V in ('dir %1\*.idx /b /s ^2^>NUL ^| find /v /c ""') do set/a dbcount = %%V
if %dbcount% GTR 0 del /s /q %1\*.idx > NUL 2>NUL

set/a fcount = %nzbcount% + %sfvcount% + %subcount% + %idxcount% + %urlcount% + %dbcount%
 
echo [Cleanup] Deleted %fcount% files (%nzbcount% nzb, %sfvcount% sfv, %subcount% sub, %idxcount% idx, %urlcount% url, %dbcount% db)
echo.
Waldorfz
Release Testers
Release Testers
Posts: 5
Joined: October 27th, 2008, 5:40 pm

Re: [Windows] Download Dir Cleaner

Post by Waldorfz »

Stupid question for you guys.  I'm new to SABnzbd so I'm still trying to figure a few things out.  I realize that post processing scripts run after the job in unpacked but do they still run if the job fails?  I'd like to use a script like this to cleanup my tv downloads.  Right now it will downloasd them and move them to a specific directory based on shaw name and season.  I'd like to get rid of all the junk (.nzb, .nfo .par2) but not if it fails.  I've had a job fail that I was able to manually repair with quickpar that the built in par2 did not fix.  If I delete all the .par2 files after a job fails than I'm kinda stuck and can't repair it.  I'd have to manually download these files again.  Any advice?
Waldorfz
Release Testers
Release Testers
Posts: 5
Joined: October 27th, 2008, 5:40 pm

Re: [Windows] Download Dir Cleaner

Post by Waldorfz »

Apparently my PAR2 issue is a setup problem due to a UNC path to the incomplete directory according to the new 4.5 RC.  I'm still curious to know if the script will run if something before it fails though for future reference.  I can't seem to find anything on that. Thanx.
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: [Windows] Download Dir Cleaner

Post by shypike »

but do they still run if the job fails
There's an option "Safe Postprocessing" (Config->Switches) which determines whether scripts re run on a failed job.
Later releases will have an extra parameter telling you what the result was.
Coeluh
Jr. Member
Jr. Member
Posts: 79
Joined: May 22nd, 2008, 1:40 pm

Re: [Windows] Download Dir Cleaner

Post by Coeluh »

Again, how do I install this?
Coeluh
Jr. Member
Jr. Member
Posts: 79
Joined: May 22nd, 2008, 1:40 pm

Re: [Windows] Download Dir Cleaner

Post by Coeluh »

What extensions does it require? It just opens a .txt now, and does nothing....
Coeluh
Jr. Member
Jr. Member
Posts: 79
Joined: May 22nd, 2008, 1:40 pm

Re: [Windows] Download Dir Cleaner

Post by Coeluh »

I put it in a file and named it cleanup.cmd, but I cant select it in SABnzbd, how can I help this?
feerlessleadr
Jr. Member
Jr. Member
Posts: 67
Joined: April 30th, 2009, 12:09 pm

Re: [Windows] Download Dir Cleaner

Post by feerlessleadr »

this is sort of in line with my other thread in this forum. 

Is there anyway to modify this script so that it will only delete the most recent file instead of all the files.

for example it will only delete the most newly created nfo in the folder?
Post Reply