• Exclusive

    Hey Guest, unlock an instant 10% bonus discount when you upgrade via the Crypoverse gateway.

Python Bulk Files Deleter (1 Viewer)

Currently reading:
 Python Bulk Files Deleter (1 Viewer)

Recently searched:

donodino88

Member
LV
2
Joined
Jun 10, 2023
Threads
10
Likes
13
Awards
6
Credits
3,061©
Cash
0$
Purger in Python it is able to delete millions of files instantly it uses future to get maximum speed, it asks user for path where the files are located then asks user to select number of threads to use for file deletion.
It also includes progress bar as well, first it scans the folder and counts how many files folder it has then it starts deletion process, along with file counts and progress bar.
Before running the script make sure to install tqdm,
pip install tqdm

import os
import concurrent.futures
from tqdm import tqdm

def delete_file(file_path):
try:
os.remove(file_path)
return file_path # Return the path of the deleted file
except PermissionError as pe:
print(f"Access Denied: {file_path}")
return None
except Exception as e:
print(f"Error deleting {file_path}: {e}")
return None

def delete_files_in_folder(folder_path, num_threads=4):
deleted_count = 0
total_count = 0

# Get a list of all files to be deleted
files_to_delete = []
for root, _, files in os.walk(folder_path):
for file in files:
file_path = os.path.join(root, file)
files_to_delete.append(file_path)
total_count += 1

with concurrent.futures.ThreadPoolExecutor(max_workers=num_threads) as executor:
# Use tqdm to create a progress bar
with tqdm(total=total_count, desc="Deleting files", unit="file") as pbar:
futures = [executor.submit(delete_file, file_path) for file_path in files_to_delete]
for future in concurrent.futures.as_completed(futures):
deleted_path = future.result()
if deleted_path:
deleted_count += 1
pbar.update(1) # Update the progress bar
pbar.set_postfix(deleted=f"{deleted_count}/{total_count}")

print("Deletion completed.")
if deleted_count == total_count:
print("All deletable files deleted successfully.")
else:
print(f"Some files could not be deleted.")

if __name__ == "__main__":
folder_path = input("Enter the path of the folder containing the files: ")

if not os.path.exists(folder_path):
print(f"Folder '{folder_path}' does not exist.")
else:
num_threads = int(input("Enter the number of threads (e.g., 4): "))

if num_threads <= 0:
print("Number of threads should be a positive integer.")
else:
delete_files_in_folder(folder_path, num_threads)
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Tips
Recently searched:

Users who are viewing this thread

Top Bottom