Q: Batch file rename
I am setting up a new NAS as a media server. When I copied over my music files the process hung up for some reason and didn't finish, other than creating the folders. When I started over, it named all of the new folders "artist 2" as overwriting the existing empty folders. Is there a way to batch rename all of these folders? I tried using Automator but it doesn't accept wildcards apparently.
I tried to Find: * 2 and Replace with *.
No joy.
Thanks.
iMac, Mac OS X (10.7.2)
Posted on Jan 22, 2016 11:54 AM
Not sure why the Automator Action to get the folders failed, however, there are other ways to walk a directory tree.
I realize that you don't need this now, but here's another method:
The Run Shell Script Action is:
function walk_tree {
local directory="$1"
local i
for i in "$directory"/*;
do
if [ "$i" = . -o "$i" = .. ]; then
continue
elif [ -d "$i" ]; then
newFolderName=$(echo "$i" | sed 's/ 2$//')
if [[ "$i" != "$newFolderName" ]]; then
if [[ ! -d "$newFolderName" ]]; then
mv "$i" "$newFolderName"
fi
fi
walk_tree "$i"
else
continue # replace continue with command to process individual file "$i" (i.e. echo "$i")
fi
done
}
walk_tree "$1"
Posted on Jan 25, 2016 7:03 AM

