[Windows] Don't put downloaded files in subfolders

Come up with a useful post-processing script? Share it here!
GHDpro
Newbie
Newbie
Posts: 1
Joined: November 7th, 2009, 7:08 am

[Windows] Don't put downloaded files in subfolders

Post by GHDpro »

Hello,

I have recently rediscovered Usenet downloading after using BT almost exclusively for a few years.

When I tried Usenet downloading through NZB a while back I used NZB-O-Matic Plus, which works great but of course only does downloading, while sabnzbd does so much more.

One annoyance I encountered with sabnzbd however is that it puts the contents of every downloaded NZB file in it's own subfolder in your download folder. As I mostly download single MKV/AVI files as single NZB files that get's annoying because you end up with lots of folders with 1 file in it.

Now I'm not sure if anyone already wrote a script that solves this issue, but if there isn't one yet, here is the one I wrote:

Code: Select all

@echo off

for /f "tokens=*" %%c in ('dir/b/a-d %1 ^| find /v /c "::"') do set filecount=%%c

if %filecount% LEQ 5 (
cd /d %1
for /f "tokens=*" %%f in ('dir /a-d /b') do if not exist "..\%%f" ( 
echo Moving %%f...
move "%%f" ".."
)
cd ..
echo Deleting folder...
rd %1
) else (
echo To many files to move, aborting...
)
Or download the script from: http://fanzub.com/downloads/move2root.zip

Basically this script will count the number of files in the subfolder. If there are 5 or less files in the folder, it'll move them to the parent folder (=root download folder). After all files have been moved it tries to remove the subfolder itself (which should be empty).

The effective result is that your root download folder will contain all downloaded files and no subfolders.

The script won't overwrite a file in the root download folder if the file already exists. In that case the duplicate file remains in the subfolder which won't get removed. The reason for the 5 file limit is to avoid moving (and potentially mixing) large collections of files.

Anyway, I'm not sure if anyone else finds this script useful, but I hope you like it.

Update 2011-10-15:
I just noticed the error barlow already noticed that not moving the files when there are more than 5 was not working. I've updated the script above to include his bugfix (thanks!).

Also note:
shypike wrote:May I point out that SABnzbd (since 0.6.3) has the option to work without job folders?
The top of the Category page says:

Ending the path with an asterisk * will prevent creation of job folders.
Finally! :) Though I'm not sure if I'll use this option in my case as my script (when now fixed at least!) will remove folders from single-file downloads but will leave multi-file downloads in folders. I suspect this option will simply not use folders for anything at all. The solution of course would be to use multiple categories, but I personally don't use the categories functionality at all (just one for everything).
Last edited by GHDpro on October 15th, 2011, 1:32 pm, edited 2 times in total.
threeclaws
Newbie
Newbie
Posts: 2
Joined: December 7th, 2009, 1:46 am

Re: [Windows] Don't put downloaded files in subfolders

Post by threeclaws »

So do I just copy the script into a text document and then give the file a .pl extension?

edit - I think I figured out that it should be a batch file.
Last edited by threeclaws on December 10th, 2009, 8:46 pm, edited 1 time in total.
chris1712
Newbie
Newbie
Posts: 3
Joined: March 21st, 2009, 8:52 pm

Re: [Windows] Don't put downloaded files in subfolders

Post by chris1712 »

Fantastic. How can I change it to rename the file to the nzb report name?

Whats a good batch guide, I'm a C programmer by trade so linux I'm happy with but batch looks so messy.
asemev
Newbie
Newbie
Posts: 4
Joined: December 10th, 2009, 3:15 pm

Re: [Windows] Don't put downloaded files in subfolders

Post by asemev »

hi guys,

i am total newbie and have no idea of how to write a script in mac os x. would you guys be willing to help me?
i also want the files to be moved to a single folder and no be kept under subfolders...
its so strange that there isnt such a setting in sabnzbd in the first place...

thanks for your help in advance.
seesaw
Newbie
Newbie
Posts: 13
Joined: February 13th, 2010, 5:18 am

Re: [Windows] Don't put downloaded files in subfolders

Post by seesaw »

Hi !

Exactly what I was looking for, thank you very much for coding that !

The only problem is that I can't get it to work.

I created a Script folder in my SABnzbd directory and put that folder's adress in the SABnzbd config/folder page.
I copied/pasted you code in a txt folder that I renamed script1.exe, went to config/switches and selected script1.exe under Default user script.

But it doesn't work, any ideas ?
doubledrat
Release Testers
Release Testers
Posts: 180
Joined: February 20th, 2008, 3:16 pm

Re: [Windows] Don't put downloaded files in subfolders

Post by doubledrat »

scripts are not .exe

rename is whatever.cmd (or .bat)
seesaw
Newbie
Newbie
Posts: 13
Joined: February 13th, 2010, 5:18 am

Re: [Windows] Don't put downloaded files in subfolders

Post by seesaw »

doubledrat wrote: scripts are not .exe

rename is whatever.cmd (or .bat)
Very nive of you, it's working fine, thanks a lot !
seraulu1
Newbie
Newbie
Posts: 1
Joined: February 21st, 2010, 9:37 am

Re: [Windows] Don't put downloaded files in subfolders

Post by seraulu1 »

Yeah that's good thankslearn hypnosis
gitar
Newbie
Newbie
Posts: 5
Joined: March 10th, 2010, 3:09 am

Re: [Windows] Don't put downloaded files in subfolders

Post by gitar »

I'm pretty new to python, but I made a script for this. Maybe someone could need it, took me a while to figure it out. :P

It will move all files from the download folder (src) one folder up (dst), checks if the file (s) is (are) there and then deletes the download folder(src).

Not sure, but the script could work on different operating systems, I only tested it on win 7 with python 2.6.4.

Code: Select all

import os,sys,shutil

src = sys.argv[1]
head, tail = os.path.split(src)
dst = head

for file in os.listdir(src):
  shutil.move(os.path.join(src,file),dst)
print "File moved ..."

if os.path.exists(dst + '\\' + file):
  shutil.rmtree(src)
  print "Directory removed ..."
  print "*** All done - Have fun ***"
else: print "Error: File not in destination directory"
barlow
Newbie
Newbie
Posts: 15
Joined: February 11th, 2008, 7:36 am

Re: [Windows] Don't put downloaded files in subfolders

Post by barlow »

GHDpro, thanks for your script :)

I ran into a slight issue with nzbs with the same name as the file they contain. In that case the file will not be moved, as the directory with the same name already exists in the parent folder. It will then proceed and try to remove the directory which will fail as the directory is not empty.

My solution is simple as it's inelegant: setting the download folder for the category to a temporary folder and then let the script move the files from there to the destination folder.
barlow
Newbie
Newbie
Posts: 15
Joined: February 11th, 2008, 7:36 am

Re: [Windows] Don't put downloaded files in subfolders

Post by barlow »

Sorry I was being an idiot...
Last edited by barlow on May 14th, 2011, 10:01 am, edited 1 time in total.
daishan
Newbie
Newbie
Posts: 4
Joined: May 20th, 2011, 7:45 pm

Re: [Windows] Don't put downloaded files in subfolders

Post by daishan »

I have a question. Both of these scripts are attacking the same problem I'm having, but from their descriptions, won't work for me.

My issue is that my sub-folders have the unpacked file, plus all the rars and other crap. Even though I have SAB set to Delete.

So I don't want to mass move all the files in the sub folder then delete the sub. How would you edit one of these to do that? I'm guessing move files with .avi or .mkv only then delete the sub and it's remaining contents?
barlow
Newbie
Newbie
Posts: 15
Joined: February 11th, 2008, 7:36 am

Re: [Windows] Don't put downloaded files in subfolders

Post by barlow »

Just a small fix:

Code: Select all

if (%filecount% LEQ 5) (
Should be:

Code: Select all

if %filecount% LEQ 5 (
As the former always is true (so files are moved regardless of the number of files in the directory).
JohnEric
Release Testers
Release Testers
Posts: 16
Joined: June 1st, 2010, 8:19 pm

Re: [Windows] Don't put downloaded files in subfolders

Post by JohnEric »

Please -- anyone,

Is there a way to add a portion of script:

deletes NFO files?



I know that SAB has this option in preferences, BUT I don't want to do it all files (since NFO is sometimes andy). I want the option of doing it for certain categories only.
alton987
Newbie
Newbie
Posts: 5
Joined: May 15th, 2011, 9:06 pm

Re: [Windows] Don't put downloaded files in subfolders

Post by alton987 »

barlow wrote: Just a small fix:

Code: Select all

if (%filecount% LEQ 5) (
Should be:

Code: Select all

if %filecount% LEQ 5 (
As the former always is true (so files are moved regardless of the number of files in the directory).
How do I add this to the larger script above?
Post Reply