Created
November 14, 2023 00:21
-
-
Save vinesmsuic/7d66c7bfed3c360d2d99d26bb6a0682a to your computer and use it in GitHub Desktop.
Only keep multiple folders with same file name. Align is the reference folder.
This file contains 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
#!/bin/bash | |
# Define the path to your root folder | |
rootFolder="." | |
# Define the path to your input folder (folderA) | |
folderA="$rootFolder/align" | |
# Function to delete excess files and print file count | |
delete_excess_files () { | |
local fileCount=0 | |
for file in "$1"/*; do | |
# Increment file count | |
((fileCount++)) | |
filename=$(basename "$file") | |
if [ ! -f "$folderA/$filename" ]; then | |
echo "Deleting $file" | |
rm "$file" | |
((fileCount--)) | |
fi | |
done | |
echo "Number of files remaining in $(basename "$1"): $fileCount" | |
} | |
# Loop through each folder in the root folder | |
for folder in "$rootFolder"/*; do | |
# Check if it's a directory and not the input folder | |
if [ -d "$folder" ] && [ "$(basename "$folder")" != "input" ]; then | |
echo "Processing $folder" | |
delete_excess_files "$folder" | |
fi | |
done | |
echo "Processing complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment