14

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]".

RomanSt
  • 9,959

5 Answers5

4

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

3

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.

Steven
  • 28,386
1

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' {} +
harrymc
  • 498,455
0

I managed with a combination of the first two answers, plus pyRenamer (GUI). Under Linux, I used pyRenamer to collapse spaces in folder names (directories) - by substituting space with nothing - so that the other programs (Glindra rename) work recursively (one could place underscores). From files, I also took out some windows-acceptable characters or words to save space, and similarly collapsed spaces in filenames. I then ran rena to take out non-windows characters, saved to a flash drive, and then used Recuva to 'restore' to a folder under Windows. Recuva indicates if a file path is too long (and it also removes non-windows characters). I have not yet found a tool that checks the path of filenames to see if they are under the Windows max limit of 255 (or say 240 to allow some leeway).

0

If your files already are on an NTFS volume, it seems that running chkdisk from Windows "solves" the problem. Unfortunately, it seems like it does so by deleting the offending files.

Peltier
  • 6,504