Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
short > long filenames?
#1
To complete my collection, can anyone tell me how to convert short filenames to long filenames?

The reverse, by Plasma:

Code:
FUNCTION short.filename$ (longname$)
longnameZ$ = longname$ + CHR$(0)
shortnameZ$ = SPACE$(128)
DIM regs AS RegTypeX
regs.ax = &H7160
regs.cx = &H1
regs.ds = VARSEG(longnameZ$)
regs.si = SADD(longnameZ$)
regs.es = VARSEG(shortnameZ$)
regs.di = SADD(shortnameZ$)
INTERRUPTX &H21, regs, regs
IF regs.ax = &H2 THEN exit.error "Invalid component in directory path or drive letter."
IF regs.ax = &H3 THEN exit.error "Malformed path or invalid drive letter."
stringEnd = INSTR(shortnameZ$, CHR$(0)) - 1
IF stringEnd < 1 THEN shortname$ = ""
ELSE shortname$ = LEFT$(shortnameZ$, stringEnd)
short.filename$ = shortname$
END FUNCTION
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#2
Code:
DEFINT A-Z
'$INCLUDE: 'QB.BI'

DECLARE FUNCTION Long.Filename$ (ShortName$)

CLS
PRINT Long.Filename$("C:\PROGRA~1\")

FUNCTION Long.Filename$ (ShortName$)

  ShortNameZ$ = ShortName$ + CHR$(0)
  LongNameZ$ = SPACE$(261)

  DIM Regs AS RegTypeX
  Regs.ax = &H7160
  Regs.cx = &H2
  Regs.ds = VARSEG(ShortNameZ$)
  Regs.si = SADD(ShortNameZ$)
  Regs.es = VARSEG(LongNameZ$)
  Regs.di = SADD(LongNameZ$)
  INTERRUPTX &H21, Regs, Regs

  IF Regs.ax = &H2 THEN
    PRINT "Invalid component in directory path or drive letter."
    EXIT FUNCTION
  ELSEIF Regs.ax = &H3 THEN
    PRINT "Malformed path or invalid drive letter."
    EXIT FUNCTION
  END IF

  StringEnd = INSTR(LongNameZ$, CHR$(0)) - 1
  IF StringEnd < 1 THEN
    LongName$ = ""
  ELSE
    LongName$ = LEFT$(LongNameZ$, StringEnd)
  END IF

  Long.Filename$ = LongName$

END FUNCTION
Reply
#3
Thank you. I will be releasing a small file lib that uses your code soon. . .l
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#4
PLASMA,
Just for the record, how does the conversion from short to long filename work? Are there any restrictions?

I was under the impression that this conversion was impossible because there is no reference of the missing (condensed) characters in the short name. If the file no longer exists, I believe you can't convert the name, unless you know you're way around the FAT and can retreat the name of the deleted original file in that manner (except the first character).

Also, if you copied the original file (having a long name) to another directory using a DOS based program, like QB, then the file in the new directory will have a filename that looks like a short name, and again I don't see how your going to convert it to a long name without any reference to the original.

If I'm wrong, please enlighten me.
*****
Reply
#5
As long as the filesystem supports long filenames, and the file was copied/created/modified with an OS that supports long filenames, it's always possible to convert short filenames to long filenames and vice versa.

The long and short filenames are both stored in the filesystem (FAT/MFT). So when you tell the OS to get the long filename, it just looks up the short filename, finds the long filename, and then returns it. The same with looking up short filenames from the long filename.

If the file no longer exists, of course you can't convert the name, because there's nothing to look up...

If you use a program that doesn't support long filenames to copy a file, the program will use the short filename, and this will be used for both the long filename and short filename of the new file. (Because the program wasn't written to support long filenames).

However, it's entirely possible to copy a file with the long filename intact...you just get the long filename of the source, then use int 21h/ax=716Ch to create the destination file with that long filename, get the short filename of the destination, and copy everything over.
Reply
#6
Quote:... However, it's entirely possible to copy a file with the long filename intact...you just get the long filename of the source, then use int 21h/ax=716Ch to create the destination file with that long filename, get the short filename of the destination, and copy everything over.
For the above case, why not do a plain old COPY?

Looks like we agree on all the other issues, except that you put it much more elegantly and more knowledgeable than I. Thanks Plasma.
*****
Reply
#7
COPY would work fine provided you are running under DOS 7.x or Win32. However, you asked about copying files using a "DOS based program like QB", which is why I explained the process. Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)