LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Convert directory structure from long file names in Linux to DOS 8.3 structure? (https://www.linuxquestions.org/questions/linux-software-2/convert-directory-structure-from-long-file-names-in-linux-to-dos-8-3-structure-752088/)

manorina 09-02-2009 08:24 AM

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?

neonsignal 09-02-2009 03:39 PM

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/'\'' *' \;
Explanation - the 'find' searches for all the directories, the 'tr' transliterate changes to uppercase, the first 's' search changes illegal characters to underscore, and the second 's' search truncates the filename and extension.

manorina 09-03-2009 01:49 AM

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

neonsignal 09-03-2009 01:54 AM

Have a look at the 'mcopy' command in the mtools package. I had assumed that your player didn't support DOS extended filenames.

manorina 09-03-2009 02:40 AM

Quote:

Originally Posted by neonsignal (Post 3667822)
Have a look at the 'mcopy' command in the mtools package. I had assumed that your player didn't support DOS extended filenames.

Thanks heaps! mtools was already installed on the system and all I had to do was edit the
Code:

/etc/mtools.conf
file to make one of the drive letters point to the device associated with the mp3 player, in my case:

Code:

/dev/sde1
so my /etc/mtools.conf file now has this entry:

Code:

drive m: file="/dev/sde1"
when I come to use mdir, I have to use sudo:

Code:

sudo mdir m:/
Anyway, thatnks once again, neonsignal

manorina 09-12-2009 09:18 AM

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.