GetShortPathName() is not working as I expect on XP SP3
http://msdn.microsoft.com/en-us/library/aa364989(VS.85).aspx
Is returning the input string for paths like:
C:\Test\LongFolderNameToTestWith\BinarySearch.ini
exactly as sent?
Yet:
C:\Documents and Settings\LocalService\NTUSER.DAT
Does make short names for the path, so I know I am calling the API correctly.
However:
C:\Documents and Settings\LocalService\BinarySearch.ini
Does not make a short name out of the filename, but does make short names for the path!?
Could someone help me understand this behavior and perhaps suggest a workaround.
Added:
I need to be able to make an 8.3 Path/filename to pass to a legacy app
How can this be done?
Added: SOLUTION
After MUCH reading/experimenting, it seems that the only reliable way to do this is using automation:
' ------------------------------------------------------------
' Library Name: Microsoft Scripting Runtime 1.0
' Library File: C:\WINDOWS\system32\scrrun.dll
' ------------------------------------------------------------
' Version Info:
' -------------
' Company Name: Microsoft Corporation
' File Description: Microsoft (R) Script Runtime
' File Version: 5.7.0.16599
' Internal Name: scrrun.dll
' Legal Copyright: Copyright (C) Microsoft Corp. 1996-2006, All Rights Reserved
' Original Filename: scrrun.dll
' Product Name: Microsoft (R) Script Runtime
' Product Version: 5.7.0.16599
' ------------------------------------------------------------
' ProgID: Scripting.FileSystemObject
' Interface Name: ScriptingFileSystemObject
'
' Interface Prefix: Scripting
This works.
A simple implementation in BASIC would be:
$PROGID_ScriptingFileSystemObject = "Scripting.FileSystemObject"
Interface Dispatch ScriptingFileSystemObject
Member CALL GetFile <&H0000271C>(IN FilePath AS STRING<&H00000000>) AS ScriptingIFile
Member CALL GetFolder<&H0000271D>(IN FolderPath AS STRING<&H00000000>) AS ScriptingIFolder
END Interface
Interface Dispatch ScriptingFile
Member GET ShortPath<&H000003EA>() AS STRING
Member GET ShortName<&H000003E9>() AS STRING
END Interface
Interface Dispatch ScriptingFolder
Member GET ShortPath<&H000003EA>() AS STRING
Member GET ShortName<&H000003E9>() AS STRING
END Interface
'-----------------------------------------------------------------------------
FUNCTION FileShortPath( BYVAL sPathnFile AS STRING, sShort AS STRING ) AS LONG
LOCAL vResult, vFilePath AS Variant
LOCAL fso AS ScriptingFileSystemObject
LOCAL oFile AS ScriptingFile
IF LEN(sPathnFile) = 0 THEN EXIT FUNCTION ' Nothing sent
SET fso = NEW ScriptingFileSystemObject IN $PROGID_ScriptingFileSystemObject
IF IsNothing(fso) THEN FUNCTION = -1 : EXIT FUNCTION
SET oFile = NEW ScriptingFile IN $PROGID_ScriptingFileSystemObject
IF IsNothing(oFile) THEN FUNCTION = -2 : EXIT FUNCTION
vFilePath = sPathnFile
vResult = Empty
OBJECT CALL fso.GetFile(vFilePath) TO vResult
SET oFile = vResult
IF IsNothing(oFile) THEN FUNCTION = -3 : EXIT FUNCTION
vResult = Empty
Object GET oFile.ShortName TO vResult
sShort = VARIANT$(vResult)
vResult = Empty
Object GET oFile.ShortPath TO vResult
sShort = VARIANT$(vResult)
IF LEN(sShort) THEN FUNCTION = 1 ' Success
END FUNCTION
Thank you all for your suggestions.