Page 1 of 1

Tried Sort Files By Group

Posted: Tue Feb 14, 2023 3:27 pm
by Pixou59
Hi ,

I would like to sort my .nzb files by groups ,

example of files :
Fatima_Hajji-Live_Set_FH_Studio_Madrid_(Maxima_FM)-SAT-09-04-2011-EiTheLMP3.nzb
Fatima_Hajji-Phrenetic_Power_Music-FM-30-12-2011-EiTheLMP3.nzb
Fliterheadz-Live_On_JJJ_The_Club-FM-12-11-2005-DOC_LIVE.nzb
Lollipop_5-Merku_Live-(10-04-2004)-CDR-2004-hM.nzb
Lucien_Foort_-_Live_at_Radio538-08-04-2001-Radio-2001-iPZ.nzb
Mampi_Swift_B2B_Brockie_-_Live_At_One_Nation-2000-sour.nzb
Psiox-Live_at_Zimmer_Frei_Natlab_Eindhoven_(Holland)-LINE-08-27-2011-TWCLIVE.nzb
Tomcraft_-_Great_Stuff_(Proton_Radio)-SBD-06-27-2012-TALiON_INT.nzb
Amitta_Hajji_aka_Fatima_Hajji-Phrenetic_Power_Music-FM-08-06-2012-EiTheLMP3.nzb
DJ_Brockie_Live_at_Master_Mix-1997-sour.nzb
DJ_Orkidea_-_Radio_Unity_26-11-2002-Cable-2002-iPZ.nzb
i tested Ultimate.Scene.Mp3.Sorter.v.1.0.Win7.WinVista-NIGHTRiDER , but it does not support files, only folders

how can i do it please ? TiA

Re: Tried Sort Files By Group

Posted: Wed Feb 22, 2023 12:21 am
by Swisha99
Rather than run some random executable, here is code to do it yourself.

Install Python - [External Link Removed for Guests]

Save the below to a file sort.py and run it in the directory with your nzb files. Note there is no error checking or handling or anything and use at own risk.... It works fine on the list of files you provided but who knows what may happen if the files have some weird symbols or something in them...

It loops through all files in the directory, checks if the end with the extension specified (nzb in this case), then splits it by hyphen and stores the last portion as the group after remove -INT and _INT. It then makes the group directory if it doesn't exist, and finally moves the files to that folder.

Edit:
Updated to account for INT releases.

Code: Select all

import os
import shutil

ext = ('.nzb') #Set Exsension. ('') for all files

directory = os.getcwd()

for filename in os.listdir(directory):
    f = os.path.join(directory, filename)
    if os.path.isfile(f):
        if f.endswith(ext):
            releasename = os.path.splitext(f)[0] 
            if releasename.lower().endswith('_int'):
                releasename = releasename[:-4]
            if releasename.lower().endswith('-int'):
                releasename = releasename[:-4]
            group = releasename.rsplit('-', 1)[-1]
            groupdir = os.path.join(directory,group,"")
            os.makedirs(os.path.dirname(groupdir), exist_ok=True)
            print("Moving: " + f + " ---> " + group)
            shutil.move(f, os.path.join(directory,group,""))
        else:
            continue    
k=input("press enter key to exit") 
0.png
0.png (47.06 KiB) Viewed 905 times
1.png
1.png (33.31 KiB) Viewed 905 times
2.png
2.png (22.78 KiB) Viewed 905 times