Board index » delphi » Convert Win95 filename into short filename

Convert Win95 filename into short filename

Hello,

I've a big problem. I have a long Win95 filename (for example:
c:\programme\Das ist ein Test.txt). How can I convert it into a short
filename (here: c:\progra~1\Dasist~1.txt with Delphi? Thanks in
advance.

(Please send a copy of your response to eb...@kamenz.de, because I
don't read Newsgroup everyday)

Ralf Ebert
eb...@kamenz.de
Sorry my bad English.

 

Re:Convert Win95 filename into short filename


Quote
Ralf Ebert wrote:
> I've a big problem. I have a long Win95 filename (for example:
> c:\programme\Das ist ein Test.txt). How can I convert it into a short
> filename (here: c:\progra~1\Dasist~1.txt with Delphi? Thanks in
> advance.

The Turbopower site at http://www.tpower.com has a nice free unit
(contained in lfn.zip I think) which handles this and many other long
filename functions in Delphi 1.0.

Andrew

Re:Convert Win95 filename into short filename


Quote
Ralf Ebert wrote:

> Hello,

> I've a big problem. I have a long Win95 filename (for example:
> c:\programme\Das ist ein Test.txt). How can I convert it into a short
> filename (here: c:\progra~1\Dasist~1.txt with Delphi? Thanks in
> advance.

        The short filename is not just a function of the long name
itself, it depends on that and on the existing files when the file
was created. So you need to ask the file system, one way or another.
One way:

var FileRec: TSearchRec;
begin
FindFirst('c:\program files', faAnyFile, FileRec);
showmessage(FileRec.Name);
showmessage(FileRec.FindData.cAlternateFileName);
FindClose(FileRec);
end;

--
David Ullrich

?his ?s ?avid ?llrich's ?ig ?ile
(Someone undeleted it for me...)

Re:Convert Win95 filename into short filename


Look in the Win32.hlp file in  \program files\borland\delphi 2.0\help and
lookup the function "GetShortPathName".  This should help you.

Re:Convert Win95 filename into short filename


Quote
Ralf Ebert wrote:

> I've a big problem. I have a long Win95 filename (for example:
> c:\programme\Das ist ein Test.txt). How can I convert it into a short
> filename (here: c:\progra~1\Dasist~1.txt with Delphi? Thanks in
> advance.

  I know this doesn't help much, but there was an API call I ran across
a while back that'll do it for you....  Hope that helps...

--
Jason
Dark...@SLSoftware.reno.nv.us

Re:Convert Win95 filename into short filename


On Wed, 02 Apr 1997 11:39:00 -0800, Jason Wallace

Quote
<Dark...@SLSoftware.reno.nv.us> wrote:
>Ralf Ebert wrote:

>> I've a big problem. I have a long Win95 filename (for example:
>> c:\programme\Das ist ein Test.txt). How can I convert it into a short
>> filename (here: c:\progra~1\Dasist~1.txt with Delphi? Thanks in
>> advance.

>  I know this doesn't help much, but there was an API call I ran across
>a while back that'll do it for you....  Hope that helps...

>--
>Jason
>Dark...@SLSoftware.reno.nv.us

Unit : SysUtils

TSearchRec = record
  Time: Integer;
  Size: Integer;
  Attr: Integer;
  Name: TFileName;
  ExcludeAttr: Integer;
  FindHandle: THandle;
  FindData: TWin32FindData;
end;
TWin32FindData is a record (structure) which contains additional file
information, one of which is the short filename used by DOS.

(Taken from WIN32.HLP)
typedef struct _WIN32_FIND_DATA { // wfd
    DWORD dwFileAttributes;
    FILETIME ftCreationTime;
    FILETIME ftLastAccessTime;
    FILETIME ftLastWriteTime;
    DWORD    nFileSizeHigh;
    DWORD    nFileSizeLow;
    DWORD    dwReserved0;
    DWORD    dwReserved1;
    TCHAR    cFileName[ MAX_PATH ];    // name of file
    TCHAR    cAlternateFileName[ 14 ]; //  8.3 format alternate file-name

Quote
} WIN32_FIND_DATA;

The WIN32_FIND_DATA structure describes a file found by the FindFirstFile or
FindNextFile function.  

So to get your short file name
  FindFirst( ' c:\programme\Das ist ein Test.txt', faAnyFile, SearchRec);
  ShortName := SearchRec.FindData.AlternateFileName;

Hope this helps.

fred p.

Re:Convert Win95 filename into short filename


Try this function to convert a filename to a short filename:

function TfrmMain.shortName(longName: PChar): PChar;
var
  shortTemp:        PChar;
begin
  shortTemp:=StrAlloc(MAX_PATH + 1);                                      
    // Pad short file name string
  getShortPathName(longName, shortTemp, strBufSize(shortTemp));            
    // Convert long file name to short
  Result:=shortTemp;
end;

Other Threads