From a39db6f4f7fe7c695abd2bd151c71fefa3f3ac13 Mon Sep 17 00:00:00 2001 From: Allen Wolf <63997543+aaw3@users.noreply.github.com> Date: Tue, 9 Jan 2024 15:13:32 -0600 Subject: [PATCH] Update WindowsRenameFix.sh --- WindowsRenameFix.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/WindowsRenameFix.sh b/WindowsRenameFix.sh index bcc903d..80bfb76 100755 --- a/WindowsRenameFix.sh +++ b/WindowsRenameFix.sh @@ -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