Retrieve the Windows short path form of the specified path.
Not available in VBA/VB6 (no useful equivalent).
long __stdcall CNV_ShortPathName(char *szOut, long nOutChars, const wchar_t* szwFilePath);
Number of characters (bytes) in or required for the output string; otherwise it returns a negative error code.
static std::string crsysapi::Cnv::ShortPathName (const std::wstring &filePath)
static Cnv.shortpathname(pathName)
Use this function to find the ASCII equivalent file path for a path represented in "Unicode" UTF-16 wchar_t
characters.
Then use this ASCII short name as an argument for an input file in any of the functions in this library that require a file name.
The file must exist. The output path is guaranteed to be in ASCII characters, and the base name and each folder name will be 8 characters or fewer. It may not give the same value on a different system. Windows only.
For the "raw" function, pass a NULL szOut or zero nOutChars to find the required output length in bytes. ANSI C users must add one to this value when allocating memory.
#include <wchar.h> long nchars; wchar_t *wfname; char *shortname; // Path name with Chinese characters wfname = L"你好.txt"; // Find required output length nchars = CNV_ShortPathName(NULL, 0, wfname); printf("CNV_ShortPathName returns %ld\n", nchars); assert(nchars >= 0); shortname = malloc(nchars + 1); nchars = CNV_ShortPathName(shortname, nchars, wfname); assert(nchars >= 0); // Output should be in ASCII printf("ShortPath='%s'\n", shortname); // ShortPath='FC0F~1.TXT' free(shortname);
#include <string> // Path name with Chinese characters std::wstring wfname = L"你好.txt"; std::string shortname = crsysapi::Cnv::ShortPathName(wfname); cout << "ShortPath='" << shortname << "'" << endl;
ShortPath='FC0F~1.TXT'
Note that the short path name may be different on your system.