Skip to content

Instantly share code, notes, and snippets.

@navicore
Created March 23, 2023 13:23
Show Gist options
  • Save navicore/0a5f6833b452906ba2588bcf99bac4c9 to your computer and use it in GitHub Desktop.
Save navicore/0a5f6833b452906ba2588bcf99bac4c9 to your computer and use it in GitHub Desktop.
import os
parent_directory = "."
required_file = "renovate.json"
# Create the output Bash script file
with open("delete_dirs_without_required_file.sh", "w") as script_file:
script_file.write("#!/bin/bash\n\n")
# Iterate through directories in the parent directory
for entry in os.scandir(parent_directory):
if entry.is_dir():
dir_path = os.path.join(parent_directory, entry.name)
target_file_path = os.path.join(dir_path, required_file)
# Check if the required file is not present in the directory
if not os.path.exists(target_file_path):
script_file.write(f'rm -rf "{dir_path}"\n')
print("Bash script 'delete_dirs_without_required_file.sh' generated.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment