Skip to content

Instantly share code, notes, and snippets.

@quentin452
Forked from makamys/zip_search.py
Last active December 26, 2023 13:06
Show Gist options
  • Save quentin452/c85e89c50b30615921a78f044570f4d7 to your computer and use it in GitHub Desktop.
Save quentin452/c85e89c50b30615921a78f044570f4d7 to your computer and use it in GitHub Desktop.
Recursive zip search
import glob
from zipfile import ZipFile, BadZipFile
import sys
import os
script_directory = os.path.dirname(os.path.realpath(__file__))
rootdir = script_directory
query = input("Enter the text you want to find: ")
names = "--names" in sys.argv
deep_scan = not names
# Load excluded extensions from the config file
config_file_path = os.path.join(script_directory, 'config.txt')
excluded_extensions = []
try:
with open(config_file_path) as config_file:
for line in config_file:
line = line.strip()
if line and not line.startswith('#'):
extension, exclude = line.split('=')
if exclude.lower() == 'true':
excluded_extensions.append(extension)
except FileNotFoundError:
pass # Handle the case where the config file doesn't exist
def scan_zip(path):
zip = ZipFile(path)
found_files = []
for name in zip.namelist():
# Check if the file extension is in the list of excluded extensions
if any(name.lower().endswith(ext) for ext in excluded_extensions):
continue # Skip excluded file types
if (deep_scan and query.encode("latin-1") in zip.read(name)) or (not deep_scan and query in name):
found_files.append(name)
return found_files
for path in glob.glob(rootdir + "/**/*", recursive=True):
if not os.path.isdir(path):
try:
found = scan_zip(path)
if found:
print("\n" + path + " contains the query in these files:\n" + "\n".join([" * " + x for x in found]))
except BadZipFile as e:
pass
except Exception as e:
print("\nException scanning", path, ":", e)
input("Press Enter to exit...")
@quentin452
Copy link
Author

quentin452 commented Dec 7, 2023

note to me : script needed to be used

Linux :

python zip_search.py /home/iamacat/.local/share/PrismLauncher/instances/Biggess\ Pack\ Cat\ Edition/minecraft/mods/ "Failed to send analytics event data."

Windows :

C:\Users\iamacatfr\AppData\Local\Programs\Python\Python312\python.exe zip_search.py "C:\Users\iamacatfr\AppData\Roaming\PrismLauncher\instances\1.7.10 Biggess Pack Cat Edition.minecraft\mods" "iceCube"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment