How to recursively rename files/folders to make their names Windows-friendly?
Solution 1
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.
Solution 2
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.
Solution 3
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' {} +
Related videos on Youtube

RomanSt
Updated on September 17, 2022Comments
-
RomanSt 4 months
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]".
-
cYrus almost 12 yearsYou should avoid such names even under Linux (especially
*
). -
HikeMike almost 12 years@cYrus Depends on how you handle files. I imagine it's only an issue with scripting and in shells. I'm on OS X and the only forbidden character is
:
, which is bad enough. Naming documents after their contents is useful, and if an article name ends with a question, so should the file name. -
RomanSt almost 12 years@cYrus and I do, in my software, but some software has been written by people who don't. For example, qmail uses : in almost every filename it creates.
-
cYrus almost 12 years@Daniel Beck: Sure, but unfortunately having a file system that supports such names it's not enough as you can use programs that mess the whole thing. I don't even use spaces.
-
cYrus almost 12 yearsGreat! Mine wasn't a solution, just an advice.
-
Peltier over 7 yearsAren't long filenames likely to be a source of problems as well?
-
Abel Cheung over 7 yearsCharacters disallowed on Windows are listed here.
-
Steven over 7 years@Peltier Would you prefer the renaming script be run in Windows or Ubuntu?
-
Peltier over 7 years@Steven good question! I think Windows would be slightly more useful, as it may happen that someone receives the files on Windows and has to fix them on that platform.
-
-
HikeMike almost 12 yearsThat page shows a 404. Google cached copy.
-
endolith almost 12 yearsDetox is for making Windows files Unix-friendly, not the other way around.
-
Ramhound over 7 years@DennisWilliamson - While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes.
-
Dennis Williamson over 7 years@Ramhound: This isn't a link-only answer. The answer is the name of two programs that do what the OP wants. The links lead to where to obtain those progtams and a reference to where I found the information.
-
Peltier over 7 years@DennisWilliamson : of the links you provided, one doesn't work anymore, the other solves a different problem, and the third one is a rant discussing that other problem.
-
Joe Taras over 7 years@Ramhound: But this is an answer of 2011!
-
Ramhound over 7 years@DennisWilliamson - The links are dead though. I am talking about the "source" link anyways not the program links.
-
Ramhound over 7 years@JoeTaras - What is your point exactly? It still is an answer, and because it only contains links, is kind of pointless 4 years later because of the dead links. Which is exactly the reason link answers are frowned upon.
-
Steven over 7 years@DennisWilliamson - It seems like glindra (for Windows) cannot rename characters with invalid filenames.
G:\spc>rena.exe -safe -portable *.txt
outputs[FATAL-ERROR] Filename syntax error: aa:a.txt
-
holroy over 7 yearsDo note that this needs to be extended with all the other illegal characters of windows, i.e.
<>:"/\|?*
-
holroy over 7 yearsDo note the change in syntax when going to Linux, that is
rena '*.*' -portable
, and if you want it recursive use something likerena '***/*.*' -portable
on Linux. And I do believe the rename should be done on Linux, not on Windows. -
Andy over 1 year@holroy can you just post the final version
-
Andy over 1 year
find: ‘rename’: No such file or directory