Tool Mass archive extractor

Apr 7, 2018
228
190
I did a simple shit to make my life bit easier after downloading gigs and gigs of assets, it basically finds and extracts all archives, maybe someone will find it handy too.


STEPS:
0. Download and install python (run in cmd "winget install python3", or do it manually).

1. Download and install 7zip.

2. Add the 7z install folder to the system environment variables.

( press win and type ENV, then go to Environment Variables and add your 7z dir to path,
sometimes you will need to run cmd again or restart your system before its added,
you will see that it is added well when you can call 7z from cmd.

3. Check the script and edit what you need, you will most likely need to change the extract path on line 32, keep the same format.

4. Copy the code into a python file with extension .py, name it whatever you like, ie unzip_all.py.

5. Put the unzip_all.py into the folder where you have all your assets zipped,
click on the directory address bar on explorer and type cmd and press enter, or run cmd and go the target dir manually,
and then just type python unzip_all.py or python3 unzip_all.py

If you are using ie DAZ3D, most of your downloaded assets will be two or even three times packed, so after using script once,
you may have to copy the script to the extract folder and run it again, if you need to run it even more times then do it with '-aos' instead of '-aoa' in the command.

Python:
import sys, os
import subprocess, colorama
print('Working directory :', os.getcwd())

def idx_builder():

    #ALL THE FORMATS YOU WANT TO FIND AND EXTRACT:
    #----------------------------------------------------------------
    extensions = ('rar', 'zip', 'tar', 'gz', '7z')
    #----------------------------------------------------------------

    all_dirs, all_files = (), ()

    for root, ds, files, in os.walk(u".", topdown=False):
        path = root.split(os.sep)
  
        for directory in ds:
            all_dirs += (directory,)
        for file in files:
            if file.split('.')[-1] in extensions:
                fwp = os.path.join(root, file)[2:]
                all_files += (fwp,)

    return all_files, all_dirs


if __name__ == '__main__':
    all_files, _ = idx_builder()

    #----------------------------------------------------------------
    #CHANGE THIS - ALL OF THE ASSETS WILL BE EXTRACTED HERE:
    target_dest = 'E:\\Downloads\\DAZ_ASSETS\\CONTENT\\TEST\\'
    # You should probably use some test directory,
    # and check the structures and files afterwards.
    # Using some important non-backed-up directory can be risky.
    #----------------------------------------------------------------

    print(all_files)
    print('FILES TO EXTRACT:', len(all_files),'to', target_dest)

    errs = 0
    for f in all_files:
        print('->', f)
        #modes : aoa - auto overwrite, aos - auto skip
        cmd = ['cmd', '/c', '7z', 'x', f, '-o' + target_dest, '-aoa']
        rc = subprocess.run(cmd).returncode
        if rc:
            print(colorama.Fore.RED + '\n [*] Error ->', colorama.Fore.GREEN+' '.join(cmd))
            print(Colorama.Style.RESET_ALL)
            os.stat(f)
            errs+=1
        else: print('OK :', ' '.join(cmd))
    print(f'ERRORS : {errs}')
 
Last edited:

⎰ ↜ ✰ BAD 75 ✰ ↜ ⎱

Forum Fanatic
Modder
May 13, 2020
5,364
46,698
Hello
I get this error

Traceback (most recent call last):
File "D:\scarico\unzip.py", line 2, in <module>
import subprocess, colorama
ModuleNotFoundError: No module named 'colorama'
 

⎰ ↜ ✰ BAD 75 ✰ ↜ ⎱

Forum Fanatic
Modder
May 13, 2020
5,364
46,698
PS D:\scarico> python zip.py
Working directory : D:\scarico
('F95Checker-Windows\\lib\\library.zip', '00_STRUMENTI.zip', '23Sisters-0.12b-pc.zip', 'apoc-patch.7z', 'Apocalypse-.1_public-pc-crunched.zip', 'BlackDoor-NovemberKing-0.25-pc.zip', 'BloodyPassion-v0.7b-BETA-pc-crunched.zip', 'BreakingBecky-0.1.2-pc.zip', 'Bringabottleofwine-0.7-win.rar', 'Cruncher-x64.zip', 'DayByDay-0.1.1-patch.zip', 'DayByDay-0.1.1-pc.zip', 'F95Checker-Windows.zip', 'Frank_2019.rar', 'Hidden_Secrets-Chapter_2_Extra-pc.rar', 'IntoTheNyxFHD-0.1-pc.zip', 'KAGTool.7z', 'Lewd-Town-Adventures-0.12.2-pc.zip', 'LTA 0.12 Italian BadRot75.rar', 'macro.rar', 'MaouSamaWeek1-Final-pc-compressed.zip', 'Occultus DoD C1R2 Italian DeepL Pro BadRot75.rar', 'OccultusDoD-c2r2-pc.zip', 'Omerta-v0.4-win.zip', 'Omerta.rar', 'SenseiOvernight_0.14.0_ita.rar', 'Stolen_Destiny_0.1.7.5_pc.zip', 'Sublime Text Build 3211 x64.zip', 'sublime_text_build_4143_x64.zip', 'TheCabin-Episode-4-pc.zip', 'TheHellcatLounge-0.10.00-pc.zip', 'TheHellcatLounge_Mod-v0.1a_KoGa3.zip', 'UAGC_v2.0.1_sdk.7z', 'Wouldyoulikeadrink8-1.0-pc.zip')
FILES TO EXTRACT: 34 to E:\Downloads\

Screenshot (393).png
what am I doing wrong?

import sys, os
import subprocess, colorama
print('Working directory :', os.getcwd())
def idx_builder():
#ALL THE FORMATS YOU WANT TO FIND AND EXTRACT:
#----------------------------------------------------------------
extensions = ('rar', 'zip', 'tar', 'gz', '7z')
#----------------------------------------------------------------
all_dirs, all_files = (), ()
for root, ds, files, in os.walk(u".", topdown=False):
path = root.split(os.sep)

for directory in ds:
all_dirs += (directory,)
for file in files:
if file.split('.')[-1] in extensions:
fwp = os.path.join(root, file)[2:]
all_files += (fwp,)
return all_files, all_dirs

if __name__ == '__main__':
all_files, _ = idx_builder()
#----------------------------------------------------------------
#CHANGE THIS - ALL OF THE ASSETS WILL BE EXTRACTED HERE:
target_dest = 'E:\Downloads\\'
# You should probably use some test directory,
# and check the structures and files afterwards.
# Using some important non-backed-up directory can be risky.
#----------------------------------------------------------------
print(all_files)
print('FILES TO EXTRACT:', len(all_files),'to', target_dest)