Board index » delphi » D1- Convert Long to Short File Names

D1- Convert Long to Short File Names

How do I convert a long file name, eg
   c:\Program Files\Microsoft Office\Office\Winword.exe
to a short one, eg
   c:\Progra~1\Micros~1\Office\Winword.exe

For reasons too numerous to mention I need to use Delphi 1 rather than 3
or 4.  I am using the WinAPI FindExecutable command to locate the
executable path for a given document type.  It all works OK but it gives
me the long version of the file name.  I want the short version for
consistency with the rest of the program.

TIA,

Dave

--
Dave Ansell
Marconi Electronic Systems
Waterlooville, England

 

Re:D1- Convert Long to Short File Names


Quote
Dave Ansell wrote in message <36631386.3...@gecm.comNOSPAM>...
>How do I convert a long file name, eg
>   c:\Program Files\Microsoft Office\Office\Winword.exe
>to a short one, eg
>   c:\Progra~1\Micros~1\Office\Winword.exe

Would you believe the function is called
GetShortPathName ?

--
Jeremy Collins

Re:D1- Convert Long to Short File Names


Quote
Jeremy Collins wrote:

> Dave Ansell wrote in message <36631386.3...@gecm.comNOSPAM>...
> >How do I convert a long file name, eg
> >   c:\Program Files\Microsoft Office\Office\Winword.exe
> >to a short one, eg
> >   c:\Progra~1\Micros~1\Office\Winword.exe

> Would you believe the function is called
> GetShortPathName ?

Yes I am sure it is in Delphi 3, but it doesn't seem to exist in Delphi
1; either that or I am looking in the wrong place.  I have searched the
API help files and its not there.  It won't compile either.  Any other
ideas?

--
Dave Ansell
Marconi Electronic Systems
Waterlooville, England

Re:D1- Convert Long to Short File Names


Quote
Dave Ansell wrote in message <3663212E.4...@gecm.comNOSPAM>...
>> Would you believe the function is called
>> GetShortPathName ?

>Yes I am sure it is in Delphi 3, but it doesn't seem to exist in Delphi
>1; either that or I am looking in the wrong place.  I have searched the
>API help files and its not there.  It won't compile either.  Any other
>ideas?

Not really (maybe if the 16-bit FindFirst function retrieves
a short filename, then you could use this). How is your
16-bit application getting hold of long filenames, anyway?

--
Jeremy Collins

Re:D1- Convert Long to Short File Names


Quote
Jeremy Collins wrote:
> Dave Ansell wrote in message <3663212E.4...@gecm.comNOSPAM>...
> >> Would you believe the function is called
> >> GetShortPathName ?

> >Yes I am sure it is in Delphi 3, but it doesn't seem to exist in Delphi
> >1; either that or I am looking in the wrong place.  I have searched the
> >API help files and its not there.  It won't compile either.  Any other
> >ideas?
> Not really (maybe if the 16-bit FindFirst function retrieves
> a short filename, then you could use this). How is your
> 16-bit application getting hold of long filenames, anyway?

The application calls FindExecutable to get a shell association for a
file. Depending on the file associations that are set up it seems to
return long file names.

Using FindFirst sounds like a good idea.  I will give it a try.

Thanks

--
Dave

Re:D1- Convert Long to Short File Names


In article <3663212E.4...@gecm.comNOSPAM>

Quote
Dave Ansell <dave.ans...@gecm.comNOSPAM> wrote:
> Jeremy Collins wrote:

>> Dave Ansell wrote in message <36631386.3...@gecm.comNOSPAM>...
>> >How do I convert a long file name, eg
>> >   c:\Program Files\Microsoft Office\Office\Winword.exe
>> >to a short one, eg
>> >   c:\Progra~1\Micros~1\Office\Winword.exe

>> Would you believe the function is called
>> GetShortPathName ?

> Yes I am sure it is in Delphi 3, but it doesn't seem to exist in Delphi
> 1; either that or I am looking in the wrong place.  I have searched the
> API help files and its not there.  It won't compile either.  Any other
> ideas?

GetShortPathName is a Win32 API call. It does not exist in the
Win16 API - but you can use "thunking" to get at it. Get the TPW32
package from my homepage. It was written mainly for Borland Pascal
7.x, but it should compile okay for Delphi 1 with very minor changes.

Best regards, The Chief
----------------------------
Dr A{*word*73}la A Olowofoyeku (The African Chief)
E-mail: la...@keele.ac.uk
Homepage: http://ourworld.compuserve.com/homepages/African_Chief/
Author of: Chief's Installer Pro v4.70 for Win16 and Win32
     ftp://ftp.demon.co.uk/pub/ibmpc/win3/apps/chief/pro/chief470.zip

Re:D1- Convert Long to Short File Names


In article <3663212E.4...@gecm.comNOSPAM>,
   Dave Ansell <dave.ans...@gecm.comNOSPAM> wrote:

Quote
>Jeremy Collins wrote:

>Yes I am sure it is in Delphi 3, but it doesn't seem to
exist in Delphi
>1; either that or I am looking in the wrong place.  I have
searched the
>API help files and its not there.  It won't compile either.
 Any other
>ideas?

I have the same problem you are encountering and have been
looking dor an answer to this question only a few days ago!
If you do a search in the Knowledge Base at
www.microsoft.com (try for instance 'long filenames' as the
kwywords), there are several articles dealing with
converting long to short filenames; these articles describe
new Win95 software interrupts (which should work under D1,
but not under D2 and above, since I understand that it is
not allowed to issue software interrupts from a 32-bit
program). I haven't tested these interrupts yet, but if you
leave me a few days, I should be able to give you a definite
answer.

Hope this helps,

REMOVE nospam. in my address

Please note our recent change of area code from
714 to 949

Quoc Thang NGUYEN
Laboratory of Cellular and
Molecular Neurobiology
Dept. of Psychobiology
University of California, Irvine
Irvine, CA92717 USA
Ph: (949) 824-4730
Fx: (949) 824-3522

Other Threads