Created
March 23, 2023 13:23
-
-
Save navicore/0a5f6833b452906ba2588bcf99bac4c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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