Working with tons of logs, especially public ones, is a nightmare. The folder is full of junk: images, binaries, garbage, all mixed in with the necessary .txt logs. Manually sorting through them is a waste of time. I wrote a Python script that cleans out unnecessary files from a directory, leaving only the .txt files for use with regex or other text processing tools.
This Python script scans the directory, finds everything that doesn't end in .txt, and deletes it.
Drag and drop the log folder or specify the path.
The script iterates through the files, deleting everything that isn't .txt. All that's left are .txt logs, ready for regex or other tools.
The script removes all the noise. No more digging through unnecessary files. It's a lightweight and targeted solution for working with large log sets.
This Python script scans the directory, finds everything that doesn't end in .txt, and deletes it.
Python:
import os
import shutil
if __name__ == "__main__":
print("══════════════════════════════════════════════════════════════")
print("Deletes all files and directories in the specified directory, \nexcept for .txt files and their containing directories.")
print("══════════════════════════════════════════════════════════════")
directory = input("Enter the directory path to clean: ")
for root, dirs, files in os.walk(directory, topdown=False):
for name in files:
if not name.endswith('.txt'):
file_path = os.path.join(root, name)
os.remove(file_path)
print(f"Deleted file: {file_path}")
if not os.listdir(root):
shutil.rmtree(root)
print(f"Deleted directory: {root}")
Drag and drop the log folder or specify the path.
The script iterates through the files, deleting everything that isn't .txt. All that's left are .txt logs, ready for regex or other tools.
The script removes all the noise. No more digging through unnecessary files. It's a lightweight and targeted solution for working with large log sets.