Okay, so for ages I've been saving files with FireFox not realising that it was making the same mistake that most programs do (including several Apple ones) and replacing forward slashes in filenames with underscores or some other symbol that I don't want.
Anyway, this means I've saved a ton of files into a folder that have underscores where they should have forward slashes that, aside from simply being wrong, breaks consistency with all the files in there that are actually correct. For those wondering why it matters; I've been saving some files with "tags" in the name in the format:
So that I can process them easily by script later on. While I could have my script watch out for this, I'm not the only one producing files like this and so and underscore is technically valid within a tag, so I want to get rid of them now.
So what I'm looking for is a unix command for finding invalid file-names and swap the underscores for slashes. So I've come up with the following from various guides from a search:
However while the find statement on its own correctly lists all the broken file-names, the mv command complains of "no such file or directory" on all files.
I'm assuming it's a problem with how I'm inserting my forward slashes; should I be using AppleScript instead for this since it interprets file-paths differently (using colons for directory separation such that slashes are fine within individual directory/file names)?
Anyway, this means I've saved a ton of files into a folder that have underscores where they should have forward slashes that, aside from simply being wrong, breaks consistency with all the files in there that are actually correct. For those wondering why it matters; I've been saving some files with "tags" in the name in the format:
Code:
MyFile [tag A/tag B/tag C]
So what I'm looking for is a unix command for finding invalid file-names and swap the underscores for slashes. So I've come up with the following from various guides from a search:
Code:
find . -name '*\[*_*\]*'|while read -r file
do
mv "'$file'" "${file//[_]/\/}"
done
I'm assuming it's a problem with how I'm inserting my forward slashes; should I be using AppleScript instead for this since it interprets file-paths differently (using colons for directory separation such that slashes are fine within individual directory/file names)?