• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1111
  • Last Modified:

Using WIN32API GetShortPathName() function

I'm trying to use the WIN32API GetShortPathName() function to return the 8.3 version of a file name.

The code that I'm using is attached, SHORTPATHNAME.PRG.

When I try running this, as in

    ? shortpathname("c:\projects\long folder name\file.ext")

then I get an error message from the GetShortPathName() call, saying

    Declare DLL call caused an exception.

Any suggestions as to what I'm doing wrong?
LPARAMETERS tfLongName

LOCAL lfShortName, lwReturn, lwShortName

DECLARE STRING GetShortPathName IN win32api AS GetShortPathName ;
	STRING @fLong, STRING @fShort, INTEGER iLength

lfShortName = SPACE(255)
lwShortName = LEN(lfShortName)

*	Call the function

lwReturn = GetShortPathName( @tfLongName, @lfShortName, lwShortName)

*	Strip away unwanted characters

lfShortName = LEFT(lfShortName, lwReturn)

CLEAR DLLS GetShortPathName

RETURN lfShortName

Open in new window

0
IainMacb
Asked:
IainMacb
  • 3
  • 2
  • 2
2 Solutions
 
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
0
 
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
0
 
IainMacbAuthor Commented:
My fault!

The DECLARE is wrong - should be DECLARE INTEGER.

Doh!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
pcelbaCommented:
You could also call ADIR function which returns the short path if the last parameter is 2. GetShortPathName is, of course, much easier to use.
0
 
IainMacbAuthor Commented:
pcelba

The downside about ADIR() as I see it is that you only get the filename, not the full path. In my example, if I do

    ADIR(array, "c:\projects\long folder name\file.ext", "", 2 )

then I get

    file.ext

- whereas what I'd really like here is the full

    C:\PROJECTS\LONGFO~1\FILE.EXT


0
 
pcelbaCommented:
Yes, I wrote GetShortPathName is much easier to use...

BTW, the most valuable resource for API calls from FoxPro is probably here: http://www.news2news.com/vfp/?function=83

LPARAMETERS lcName

LOCAL lnI, lnFiles, laF[1], lcResult, lcSubPath, lcToProcess

lcToProcess = lcName
lcResult = ''
lcSubPath = ''

DO WHILE LEN(lcToProcess) > 0
  lcSubPath = lcSubPath + IIF('\'$lcToProcess, LEFT(lcToProcess, AT('\', lcToProcess)), lcToProcess)
  lcToProcess = IIF('\'$lcToProcess, SUBSTR(lcToProcess, AT('\', lcToProcess)+1), '')
  IF RIGHT(lcSubPath, 2) == ":\"
    lcResult = lcResult + lcSubPath
  ELSE
    lnFiles = ADIR(laF, lcSubPath + '.', 'D', 2)
    IF lnFiles = 0
      *lcResult = ''
      EXIT
    ELSE
      lcResult = lcResult + laF[1,1] + IIF(LEN(lcToProcess) > 0, '\', '')
    ENDIF
  ENDIF
ENDDO

RETURN lcResult

Open in new window

0
 
IainMacbAuthor Commented:
The last link is very useful in that it gives API calls using VFP code.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now