After reading the answers to this very interesting question and doing some experimenting with SD card for Android (exfat) and a car entertainment system (vfat), I came up whis this little bash script.
#! /bin/bash
DST=$1
# copy music to FAT media
find music/ Music/ -type f | while read f ; do
d=$DST/$( echo $f | sed 's/[^-A-Za-z0-9/._ ()]/_/g' )
echo :$d:
mkdir -p "$(dirname "$d")"
cp -n "$f" "$d"
done
It take the destination (mount point) as it argument and use find
to locate all files in my music repository.
For each file path, it computes a destination path and file name by prepending the destination and replacing any offending character with an underscore _
. I use a white list of characters (letters, digits, -
, /
, .
,
. (
, )
and _
) to remove any unwanted punctuation.
Depending on the locale, this will leave accented letters in the path and file name, which is OK for modern FAT file systems, as it seems.
For each destination file path and name, the directories are created as needed using mkdir -p
, then the file is copied, unless it already existed.
Note the quote "
chars in various places, they are required to keep paths and names with spaces in them from breaking apart.
Nice - haven't used pax before. Thanks for putting me on to it. – mo-seph – 2010-08-19T21:45:41.203
1Backslash also makes problems to vfat. Include it in the regexp as well. Thanks! – lzap – 2011-11-18T09:50:03.550
The full list according to http://support.grouplogic.com/?p=1607 is: / ? < > \ : * | ” ^. Also it cannot end with space or dot and some names are reserved. Mtools manpage gives even bigger list: , ; : ? + * = [ ] < > ' " \ / |
– dhill – 2012-03-29T14:30:21.803And a different note and for people having the same issue as me: pax does not support using -s in combination with the update command -u. I.e. it will always copy renamed files again even if they already exist. It took me hours to find out about that.
– balu – 2014-01-23T21:32:30.707