Board index » delphi » 8.3 filenames/paths

8.3 filenames/paths

Does anyone know of a function or procedure that will convert long filenames
and paths to the
8.3 DOS format (eg C:\Program Files would become C:\progra~1)  ?   I need
the user to be able to see
the long filenames but have the code convert it once a directory has been
selected.

Many thanks in advance

Peter de Mestre
Australia

 

Re:8.3 filenames/paths


In article <6uhf1c$gt...@reader1.reader.news.ozemail.net>, "Peter de Mestre"

Quote
<demes...@gil.com.au> writes:
>Does anyone know of a function or procedure that will convert long filenames
>and paths to the
>8.3 DOS format (eg C:\Program Files would become C:\progra~1)  ?   I need
>the user to be able to see
>the long filenames but have the code convert it once a directory has been
>selected.

Use the Delphi FindFirst function and then access :-

F.FindData.cFileName  - (long filename)
F.FindData.cAlternateFileName  - ( 8.3 filename)

(F is the same TSearchRec as is mentioned in Delphi help file for FindFirst)

Alternatively use the FindFirstFile API routine in a similar way.

Alan Lloyd
alangll...@aol.com

Re:8.3 filenames/paths


If you're working in 16-bit windows (Delphi 1 only), the following function
will work

function ConvertToShortFileName(FileName : string) : string;
{$ifndef win32}
var
  ShortFileName : string;
  i            : integer;
  Offs1,
  Offs2,
  Seg1,
  Seg2         : word;
  Err          : boolean;
  fil          : file;
{$endif}
begin
{$ifdef win32}
  Result := FileName;
{$else} { 16-bit windows only }

  if (FileName <> '') and (DosVersion >= 7) then
    begin
      if not FileExists(FileName) then  { Create file if it doesn't exist }
        begin
          AssignFile(fil, FileName);
          rewrite(fil, 1);
          i := IoResult;
          CloseFile(fil);
          i := IoResult;
        end;

      FileName := FileName+Nul;
      ShortFileName := '' + Nul;
      Err := False;
      Offs1 := longint(@FileName[1]);
      Offs2 := longint(@ShortFileName[1]);
      Seg1  := longint(@FileName[1]) shr 16;
      Seg2  := longint(@ShortFileName[1]) shr 16;
      asm
        push ds
        mov ax, 7160h
        mov cl, 1
        mov ch, 0
        mov si, [Seg1]
        mov ds, si
        mov si, [Offs1]
        mov di, [Seg2]
        mov es, di
        mov di, [Offs2]
        int 21h
        jc @Seterror
        jmp @NoError
      @Seterror:
        mov Err, True
      @NoError:
        pop ds
      end;
    end
  else
    begin
      Result := '';
      exit;
    end;

  if err then
    begin
      dec(FileName[0]);
      Result := FileName;
    end
  else
    begin
      i := 1;
      while (ShortFileName[i] <> Nul) do
        inc(i);
      ShortFileName[0] := Chr(i-1);
      if Err then
        ShortFileName := '';
      Result := ShortFileName;
    end;
  {$endif}
end;  { ConvertToShortFileName }

Re:8.3 filenames/paths


I need same thing... Please mail me if you know how to do it... thnx

Quote
Peter de Mestre wrote in message

<6uhf1c$gt...@reader1.reader.news.ozemail.net>...
Quote
>Does anyone know of a function or procedure that will convert long
filenames
>and paths to the
>8.3 DOS format (eg C:\Program Files would become C:\progra~1)  ?   I need
>the user to be able to see
>the long filenames but have the code convert it once a directory has been
>selected.

>Many thanks in advance

>Peter de Mestre
>Australia

Re:8.3 filenames/paths


Thanks Rick,

Unfortunately I'm using Delphi 3 on Win95/98 and NT

Best Regards,

Peter de Mestre

Quote
Peter de Mestre wrote in message

<6uhf1c$gt...@reader1.reader.news.ozemail.net>...
Quote
>Does anyone know of a function or procedure that will convert long
filenames
>and paths to the
>8.3 DOS format (eg C:\Program Files would become C:\progra~1)  ?   I need
>the user to be able to see
>the long filenames but have the code convert it once a directory has been
>selected.

>Many thanks in advance

>Peter de Mestre
>Australia

Re:8.3 filenames/paths


You'll find an answer at http://www.chami.com/tips/delphi/110896D.html

Peter de Mestre <demes...@gil.com.au> a crit dans l'article
<6uhf1c$gt...@reader1.reader.news.ozemail.net>...

Quote
> Does anyone know of a function or procedure that will convert long
filenames
> and paths to the
> 8.3 DOS format (eg C:\Program Files would become C:\progra~1)  ?   I need
> the user to be able to see
> the long filenames but have the code convert it once a directory has been
> selected.

> Many thanks in advance

> Peter de Mestre
> Australia

Re:8.3 filenames/paths


Peter,

The problem with 8.3 filenames is that the resulting filename depends
on  the contents of the directory. The formula is quite easy:

Firstly, the spaces are removed from the filename, as well as all of the
fullstops (except the last one for the EXT)

then the first 6 characters are identical (uppercase), then a tilde (~)
and then a number (more about that later). The extension is the
uppercase of the first 3 letters of the last extension. This will only
happen if the lfn is either longer than 8.3, or if there are 2 or more
fullstops(.), or a space in the file.

The number is the number of the file in the directory which is saved in
that format.

For example:

Create a file

mybigfile.html

it will be called mybigf~1.htm

and then create another file

"My Big File.html"

and it will be called mybigf~2.htm

So the real problem in finding a file is to guess which file is being
referenced!!

Also if you are planning on saving in this format, DONT!! what you save
as will be preserved within lfn compatable os's

David Russell

Quote
Peter de Mestre wrote:

> Does anyone know of a function or procedure that will convert long filenames
> and paths to the
> 8.3 DOS format (eg C:\Program Files would become C:\progra~1)  ?   I need
> the user to be able to see
> the long filenames but have the code convert it once a directory has been
> selected.

> Many thanks in advance

> Peter de Mestre
> Australia

Re:8.3 filenames/paths


You can use the "SendDlgItemMessage(hDlg, IDD_FNAME, EMLIMITTEXT, 12, 0)"
 THis will force it to a 8x3 plus your '.'

Peter de Mestre <demes...@gil.com.au> wrote in article
<6uhf1c$gt...@reader1.reader.news.ozemail.net>...

Quote
> Does anyone know of a function or procedure that will convert long
filenames
> and paths to the
> 8.3 DOS format (eg C:\Program Files would become C:\progra~1)  ?   I need
> the user to be able to see
> the long filenames but have the code convert it once a directory has been
> selected.

> Many thanks in advance

> Peter de Mestre
> Australia

Other Threads