How to recursively rename files/folders to make their names Windows-friendly?
I have a bunch of files on a Ubuntu box, which have various characters in their filenames that Windows doesn't accept (mostly ":" and "*", but possibly others).
What's the simplest way to get these all renamed and moved to a Windows machine? It's OK to replace these characters with something like "[colon]" and "[asterisk]".
Take a look at Glindra rename and detox.
Glindra file utilities can be installed on either Windows or Linux. Examples of cleaning up file names on Windows:
rena *.* -portable
rena *.* -safe
-
-safe
Maps leading dashes (hyphens) to underscores.
Collapses spaces.
Maps problematic characters like *?:[]"<>|(){} to underscore. -
-portable
Performs the same cleanup operations as -safe, and additionally:
Maps all 8-bit characters from the upper half of the Latin 1 alphabet to reasonable 7-bit fallback characters.
Maps the single quote characters '`´ to underscore.
Source: Fixing Unix/Linux/POSIX Filenames: Control Characters (such as Newline), Leading Dashes, and Other Problems
Try Recuva.
It is the the only Windows utility I have found which handles non-Windows friendly filenames.
Enable Scan for non-deleted files (for recovery from damaged or reformatted disks) and scan your folder. On restore, enable Restore folder structure. Recuva will effectively "copy" the entire directory to another location while "santitizing" unfriendly filenames.
Without being on Linux and without testing anything, I believe that one could use one-liners like the ones below.
To change one character :
find . -type f -exec rename 's/:/\[colon\]/g' {} +
find . -type f -exec rename 's/\*/\[asterisk\]/g' {} +
And finally to remove all non-alphanumeric characters :
find . -type f -exec rename 's/[^A-Za-z0-9._]//g' {} +