Skip to main content
XsiSec.com
HomeReposBlogProjectsPortfolio
© 2026 XsiSec.com
Security rules |security.txt
Updated 2026-08-15 · v1.0.0+2026-08-14.82f92cb · 82f92cb
← Back to overview
Security article

Python script to extract recursive folders

Python script to extract recursive folders: sql • Other • other, python

2023-04-112 tags
Tags
sql
Last Weekend I wrote a python script the purpose is to pick a folder where the script recursive search through all nested folders for "*.rar" files.
```sql
```sql
 In first place you pick a Target folder where you have all rar files and a destination where you want to extract.

Quite straight forward:

python
#!/usr/bin/python import errno import os, zipfile, pyunpack, sys import tkinter as tk from tkinter import filedialog from tkinter.filedialog import askdirectory cwd = os.getcwd() root = tk.Tk() root.withdraw() desktop ='C:/Somehardcoded unrar folder not in used per default' target='C:/somehardcoded unrar target folder not used per default' #basis_folder = file rar_files_folder = askdirectory(title='Select Folder') output_folder = askdirectory(title='Select Folder') for subdir, dirs, files in os.walk(rar_files_folder): for file in files: for root, dirs, files in os.walk(rar_files_folder): for filename in files: if filename.endswith(".rar"): print('Found rar files in:' + os.path.join(root, filename)) elif filename.endswith(".zip"): print('ZIP:' + os.path.join(root, filename)) name = os.path.splitext(os.path.basename(filename))[0] if filename.endswith(".rar") or filename.endswith(".zip"): try: arch = pyunpack.Archive(os.path.join(root, filename)) # os.mkdir(name) arch.extractall(directory=output_folder) except Exception as e: print("ERROR: BAD ARCHIVE " + os.path.join(root, filename)) print(e) try: # os.path.join(root,filename)os.remove(filename) pass except OSError as e: # this would be "except OSError, e:" before Python 2.6 if e.errno != errno.ENOENT: # errno.ENOENT = no such file or directory raise # re-raise exception if a different error occured sys.exit() os._exit(0)
Search
Explore

Popular tags

Browse all 30 tags

Comments

0 comments

No comments yet — be the first to comment.