On 25/08/2019 21.29, David Haller wrote:
Hello,
On Sun, 25 Aug 2019, Carlos E. R. wrote:
I need to copy some files to an USB stick (FAT). The problem is, the files have a ":" on their names, and Thunar (XFCE) says the name is invalid, but does not offer as an option to change the name. [..] Midnight commander does not allow edit. Well, it does, in a cumbersome manner.
Try this in your local/user/system menu-extension file (F9 -> c -> m -> [local/user/system]):
==== the "F" at the start of each second line is the shortcut ==== + ! t t F cp-rename to FAT-compatible filenames to=$(echo "%f" | tr ':\\' '__') cp "%d/%f" "%D/$to"
+ t t F cp-rename to FAT-compatible filenames for i in %s ; do to=$(echo "$i" | tr ':\\' '__') cp "%d/$i" "%D/$to" done ====
The use "F2", "F" to copy the selected file(s) to the other directory.
That's a very good idea! I often forget this "mc" feature. I just googled "sanitize filename for FAT", and found "npm", but there is no package. There may be others.
You could also add recode/iconv into the mix to convert filenames, but that should be handled by the iocharset of the fat-mount. ISTR, that ':' and '\' are the only chars disallowed on FAT (modulo the charset and up-/downcase collisions handled by the kerneldriver). Anyway, you can basically do lots instead of that simple 'tr'.
I use ":" often, but never "/" or "\".
Tested with:
$ ls * a: b:ö b:ö\x ä:x ä:y
b: b_ö b_ö_x ä_x ä_y
and copying one/all files from ./a to ./b using 'mc a b'...
IMO, the most difficult part is choosing an appropriate menu-key ;)
Oh, I have some using double letters - I run out of ideas for naming them, and making sure there are no collisions ;-) -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)