Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding out the 16-bit filename 1

Status
Not open for further replies.

carpeliam

Programmer
Joined
Mar 17, 2000
Messages
990
Location
US
I'm working with a program that needs the old DOS 8.3 16-bit filename... is there a way to find that information out?

Say, for example, I have one text file that has this line:

File16=Good News 42.txt

and I want to write (to a seperate file) the line (as follows)

GOODN~42.TXT

so far I can only write "Good News 42.txt".. and there's no corelation (other than implied) between the two seperate "42"s.

Thanks for any help you can give me, or pointers in any direction. Liam Morley
lmorley@wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
 
Well, this seemed like a neat challenge, and a chance to expand my bag o' tricks, so...

You can do this in two lines, but mind you, they're long and convoluted lines. But two lines, no less. I assume an array @f that contains the long filenames, and end with an array @msdos containing the 16-bit names.
Code:
#!/usr/bin/perl

@l=sort{$a->[0] cmp $b->[0]}map{s/\s+//g;($_,my$e)=split
/\.(\w+$)/;s/\.|\W!\-//g;tr///c<8?[$_,$e,0,0]:[$_,$e,1,1]}
@f;

@msdos=map{my($i,$n)=(1,shift(@l));my$s=substr($n->[0],0,6);
grep{$_->[0]=~/^$s/&&$n->[1]eq$_->[1]&&$n->[2]==1?$_->[3]++
:1}@l;$n->[2]?substr($n->[0],0,7-length($n->[3])).&quot;~&quot;.
$n->[3].'.'.substr($n->[1],0,3):$n->[0].'.'.
substr($n->[1],0,3)}0..@l;
Now, I leave it as an exercise to the reader to figure out what's going on there. It's not as complicated as it might apppear. A star for the first person to post an accurate analysis. This is just my first shot, so I haven't conducted any optimization... So on that note, another star for anyone that optimizes this and posts the new code with the benchmark results.

Take care!

brendanc@icehouse.net
 
The formatting didn't last on that post, did it? Well, the double linebreaks signify the seperation between the two lines.. everything else can be concatenated.

brendanc@icehouse.net
 
This isn't an analysis of the code, but an pretty extensive (and TESTED) analysis of the problem.

OK, we know that if the file name is more than 8 characters long the dos name is the first six characters (ignoring blanks), a tilde, and a 1-digit number. And if the first six characters are the same as another file the number increments. Also, if the &quot;extension&quot; is longer than 3 characters it truncates it. BUT:

Q: What does it do it ther are more than 9 files with the first six characters duplicated?

A: It uses the first FIVE characters, a tilde, and a 2-digit number!

Q: Which order does it look at the files in? This affects which one is ~1 and which is ~2, etc.

A: This one is a LOT trickier. It apparently looks at them in the order they are stored in the directory entries. BUT: THE NUMBER DOESN'T ALWAYS START WITH 1!!! I created a bunch of files and listed them. Got ~1 thru ~15. Then I deleted ~1, ~2 and ~3. When I listed them again I got ~4 thru ~15! Apparently it looks at DELETED directory entries too! When I saved a file with the same name as the one that show up as ~1, then ~1 was BACK, but ~2 and ~3 are still skipped.

THEREFORE: I don't think you CAN simply tranlate a file name into it's dos equivalent! It seems to depend too much on the directory entries (including deleted ones).
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Well.. the idea of this exercise was to take in a list of filenames and return a list of equivalents *in the context of the list*, not the filesystem. If you want to get 8.3 filenames in the latter context, simply do a regular expression on `dir /w`.

As for your first Q:, regarding the 5 character termination...This is how DOS treats the same situation; is it not? Did the script fail to do that? The only thing I see wrong with this routine is that it keeps the regex matching 6 characters instead of 5 (or 4 if you go into the hundreds, and so on)...But that can be changed with a slight modification to the substr where $s is declared. Other than that, it appears to work fine over here.

brendanc@icehouse.net
 
the problem is, the list is a subset of the directory structure, so I need it in terms of the file system (for example, I had one file called CANDLE~2 that I had downloaded after downloading CANDLE~1 and CANDLE~3; it wrote over CANDLE~1 for reasons that aren't too hard to discover, but it's a real pain). I've got some files that go up to ~11, so I do have to worry about those cases.<br><br>The reason I wasn't so keen on doing a reg exp on `dir /w` is because there are over 2,000 files in the directory, so I didn't really want to query the entire directory, which would take a bit longer than desired. Of course, if it's the only way to do it... <p>Liam Morley<br><A HREF="mailto:"></A><br>&quot;light the deep, and bring silence to the world.<br>light the world, and bring depth to the silence.&quot;
 
imotic: you could do a regex on `dir /w filespec` and that should work without too many files to process.

sophisticate: I didn't say what you had wouldn't work. I was just pointing out the difficulties involved. I also can't see what good it would do to convert a list of filenames if it WASN'T in the context of the filesystem. Unless you were just doing it as an exercise, as you point out. The code is good, I'm just not sure how USEFUL it is.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
aah, that works nicely without too much work.. I had another personal problem with using system calls, but I suppose there isn't much of a way around that, is there? :o) (seeing as how system calls are a real essential part of the problem)<br><br>I'd give you a star, but it seems you already got one for the answer.. thank you. <p>Liam Morley<br><A HREF="mailto:"></A><br>&quot;light the deep, and bring silence to the world.<br>light the world, and bring depth to the silence.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top