LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 09-02-2009, 08:24 AM   #1
manorina
LQ Newbie
 
Registered: Jan 2008
Location: Eastern Australia
Distribution: Mint 6, 7, Ubuntu 9.04
Posts: 18

Rep: Reputation: 1
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?
 
Old 09-02-2009, 03:39 PM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Wheezy (Fluxbox WM)
Posts: 1,363
Blog Entries: 52

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
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.

Last edited by neonsignal; 09-02-2009 at 03:40 PM.
 
Old 09-03-2009, 01:49 AM   #3
manorina
LQ Newbie
 
Registered: Jan 2008
Location: Eastern Australia
Distribution: Mint 6, 7, Ubuntu 9.04
Posts: 18

Original Poster
Rep: Reputation: 1
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 ...
 
Old 09-03-2009, 01:54 AM   #4
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Wheezy (Fluxbox WM)
Posts: 1,363
Blog Entries: 52

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

Last edited by neonsignal; 09-03-2009 at 01:55 AM.
 
Old 09-03-2009, 02:40 AM   #5
manorina
LQ Newbie
 
Registered: Jan 2008
Location: Eastern Australia
Distribution: Mint 6, 7, Ubuntu 9.04
Posts: 18

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by neonsignal View Post
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
 
Old 09-12-2009, 09:18 AM   #6
manorina
LQ Newbie
 
Registered: Jan 2008
Location: Eastern Australia
Distribution: Mint 6, 7, Ubuntu 9.04
Posts: 18

Original Poster
Rep: Reputation: 1
perl script to do the trick ...

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!
Attached Files
File Type: txt m3u_perl_script.txt (7.4 KB, 62 views)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
wget input file and directory structure Eddie1506 Linux - Software 3 05-14-2009 08:26 AM
Bash script to download a directory structure and a file... JoeBleaux Programming 2 03-21-2009 11:21 AM
how many different ways we can remove the file from a directory structure. dina3e Linux - General 8 10-01-2008 03:06 AM
Home Jail Folder Structure like Gobolinux Directory Structure luispt Linux - General 3 07-26-2008 06:46 PM
Directory structure in linux hero Linux - Newbie 1 09-04-2003 03:55 AM


All times are GMT -5. The time now is 01:39 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration