Convert directory structure from long file names in Linux to DOS 8.3 structure?
Hi All,
I've been looking high and low for a utility program or perl script or something that can take a linux directory structure as input and convert it to MS-DOS 8.3 directory structure. The purpose of this is to conform to the path format that is expected on my rather old Creative Zen Neeon MP3 player for m3u play lists. Any ideas? |
Some of this can be done with rename, though it is a bit crude (and doesn't handle name clashes or filenames without an extension):
Code:
find . -type d -exec bash -c 'cd "{}"; rename '\''tr/a-z/A-Z/;s/[ "*:<>?|]/_/g;s/(.{0,8}).*\.(.{0,3}).*/$1.$2/'\'' *' \; |
Thanks neonsignal. That certainly helps. The harder problem is really sorting out the handling of long file names that do "clash" in 8.3 format as nearly all the files I will be dealing with have this problem, eg:
/home/Music/Bob Dylan - Hurricane.mp3 /home/Music/Bob Dylan - Isis.mp3 needs to become \HOME\MUSIC\BOBDYL~1.MP3 \HOME\MUSIC\BOBDYL~2.MP3 etc etc. So I really do have to worry about chars that aren't allowed in MS-DOS file names and getting the ~n thing right which means needing to know everything about the directory structure. Another thought I've had is this: Is it possible to force Linux to read or list the shortnames on a VFAT mounted filesystem? It seems that when mounting a VFAT media device, Linux will always preferentially list the long file name entry rather than the shortname (8.3 format) entry. I might start this as a new thread ... |
Have a look at the 'mcopy' command in the mtools package. I had assumed that your player didn't support DOS extended filenames.
|
Quote:
Code:
/etc/mtools.conf Code:
/dev/sde1 Code:
drive m: file="/dev/sde1" Code:
sudo mdir m:/ |
perl script to do the trick ...
1 Attachment(s)
Well, I got all excited about the mtools package and then discovered there was a bit more to it than that. Having a chance to revisit the problem, I decided to dabble in Perl and write my own script to do the job. It's pretty crude and not at all elegant, but if it might be of use to whoever needs some kind of starting point to do their own solution, I attach the code to this post.
Happy hacking! |
All times are GMT -5. The time now is 09:30 PM. |