CryptoSys API Library Manual


Retrieve the Windows short path form of the specified path.

VBA/VB6 Syntax

Not available in VBA/VB6 (no useful equivalent).

C/C++ Syntax

long __stdcall CNV_ShortPathName(char *szOut, long nOutChars, const wchar_t* szwFilePath);


[out] Buffer to receive output.
[in] Maximum length of output string in bytes (excluding the terminating null).
[in] Path name in wide characters.

Returns (VBA/C)

Number of characters (bytes) in or required for the output string; otherwise it returns a negative error code.

.NET Equivalent

Cnv.ShortPathName Method

C++ (STL) Equivalent

static std::string crsysapi::Cnv::ShortPathName (const std::wstring &filePath)

Python Equivalent

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'
#include <string>
// Path name with Chinese characters
std::wstring wfname = L"你好.txt";
std::string shortname = crsysapi::Cnv::ShortPathName(wfname);
cout << "ShortPath='" << shortname << "'" << endl;

Note that the short path name may be different on your system.

See Also

[Contents] [Index]

[PREV: CNV_HexStrFromBytes...]   [Contents]   [Index]   
   [NEXT: COMPR_Compress...]

Copyright © 2001-23 D.I. Management Services Pty Ltd. All rights reserved. Generated 2023-05-27T11:37:34Z.