Note that there are some explanatory texts on larger screens.

plurals
  1. POShort file names versus long file names in Windows
    primarykey
    data
    text
    <p>I have some code which gets the short name from a file path, using GetShortNameW(), and then later retrieves the long name view GetLongNameA().</p> <p>The original file is of the form</p> <pre><code>"C:/ProgramData/My Folder/File.ext" </code></pre> <p>However, following conversion to short, then back to long, the filename becomes</p> <pre><code>"C:/Program Files/My Folder/Filename.ext". </code></pre> <p>The short name is of the form</p> <pre><code>"C:/PROGRA~2/MY_FOL~1/FIL~1.EXT" </code></pre> <p>The short name is being incorrectly resolved.</p> <p>The code compiles using VS 2005 on Windows 7 (I cannot upgrade the project to VS2008)</p> <p>Does anybody have any idea why this might be happening?</p> <pre><code> DWORD pathLengthNeeded = ::GetShortPathNameW(aRef-&gt;GetFilePath().c_str(), NULL, 0); if(pathLengthNeeded != 0) { WCHAR* shortPath = new WCHAR[pathLengthNeeded]; DWORD newPathNameLength = ::GetShortPathNameW(aRef-&gt;GetFilePath().c_str(), shortPath, pathLengthNeeded); if(newPathNameLength != 0) { UI_STRING unicodePath(shortPath); std::string asciiPath = StringFromUserString(unicodePath); pathLengthNeeded = ::GetLongPathNameA(asciiPath.c_str(),NULL, 0); if(pathLengthNeeded != 0) {// convert it back to a long path if possible. For goodness sake can't we use Unicode throughout?F char* longPath = new char[pathLengthNeeded]; DWORD newPathNameLength = ::GetLongPathNameA(asciiPath.c_str(), longPath, pathLengthNeeded); if(newPathNameLength != 0) { std::string longPathString(longPath, newPathNameLength); asciiPath = longPathString; } delete [] longPath; } SetFullPathName(asciiPath); } delete [] shortPath; } </code></pre>
    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.
    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