Note that there are some explanatory texts on larger screens.

plurals
  1. POGetShortPathName unpredictable results
    primarykey
    data
    text
    <p>GetShortPathName() is not working as I expect on XP SP3</p> <p><a href="http://msdn.microsoft.com/en-us/library/aa364989(VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa364989(VS.85).aspx</a></p> <p>Is returning the input string for paths like: </p> <pre><code>C:\Test\LongFolderNameToTestWith\BinarySearch.ini </code></pre> <p>exactly as sent?</p> <p>Yet: </p> <pre><code>C:\Documents and Settings\LocalService\NTUSER.DAT </code></pre> <p>Does make short names for the path, so I know I am calling the API correctly.</p> <p>However: </p> <pre><code>C:\Documents and Settings\LocalService\BinarySearch.ini </code></pre> <p>Does not make a short name out of the filename, but does make short names for the path!?</p> <p>Could someone help me understand this behavior and perhaps suggest a workaround.</p> <p><strong>Added:</strong></p> <p><strong>I need to be able to make an 8.3 Path/filename to pass to a legacy app</strong></p> <p><strong>How can this be done?</strong></p> <p><strong>Added: SOLUTION</strong></p> <p>After MUCH reading/experimenting, it seems that the only reliable way to do this is using automation:</p> <pre><code>' ------------------------------------------------------------ ' 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 </code></pre> <p>This works. </p> <p>A simple implementation in BASIC would be:</p> <pre><code>$PROGID_ScriptingFileSystemObject = "Scripting.FileSystemObject" Interface Dispatch ScriptingFileSystemObject Member CALL GetFile &lt;&amp;H0000271C&gt;(IN FilePath AS STRING&lt;&amp;H00000000&gt;) AS ScriptingIFile Member CALL GetFolder&lt;&amp;H0000271D&gt;(IN FolderPath AS STRING&lt;&amp;H00000000&gt;) AS ScriptingIFolder END Interface Interface Dispatch ScriptingFile Member GET ShortPath&lt;&amp;H000003EA&gt;() AS STRING Member GET ShortName&lt;&amp;H000003E9&gt;() AS STRING END Interface Interface Dispatch ScriptingFolder Member GET ShortPath&lt;&amp;H000003EA&gt;() AS STRING Member GET ShortName&lt;&amp;H000003E9&gt;() 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 </code></pre> <p>Thank you all for your suggestions.</p> <hr> <p>I am still trying to find a way to reliably make an 8.3 Path/filename.</p> <p>Is there any way to do this apart from using GETSHORTPATHNAME?</p> <p>Solved. See above</p> <p>It seems that MS has continued support for this for COM deciples only... why it is now unreliable in the C API remains a mystery.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload