Update WindowsRenameFix.sh

This commit is contained in:
Allen Wolf
2024-01-09 15:13:32 -06:00
parent 6a95b05553
commit a39db6f4f7

View File

@ -1,8 +1,20 @@
#!/bin/bash
echo read the comments in this file see a fix
# Old version:
# for f in ./*'('*')'*; do mv -i "$f" "${f/ (*)/}"; done
# for f in ./*/*'('*')'*; do mv -i "$f" "${f/ (*)/}"; done
# for f in ./*/*'('*')'*; do mv -i "$f" "${f/ (*)/}"; done
# etc, for the directory you're in that you want to fix.
# I know this is a garbage implementation, but not the best at bash scripting, so don't know how to recurse through each individual directory
#!/bin/bash
# Recursively find all files with parentheses in the name
find . -type f -name '*(*' -print0 | while IFS= read -r -d '' file; do
# Extract the new filename without parentheses
new_name=$(echo "$file" | sed 's/ ([^)]*)//g')
# Check if the new name is different from the current name
if [ "$file" != "$new_name" ]; then
# Rename the file
mv -i "$file" "$new_name"
echo "Renamed: $file to $new_name"
fi
done