Главная страница | назад





Article #17529: How to get a long file name from a short one

 Question and Answer Database
FAQ2529C.txt How to get a long file name from a short one
Category :Windows API
Platform :All
Product :C++Builder 3.x
Question:
How do I get the long file name if I only have the truncated
short one?
Answer:
Include the file shlguid.h and use the function below — modified for VCL
use.
This will give the CORRECT longfilename regardless of where shortname
truncation occurs (directory or file).
//
// include header
//
#include 
//
// function to determine long name
//
void __fastcall miscGetLongName( AnsiString& a )
{
//
// get desktop folder
//
IShellFolder *desktop;
if ( SHGetDesktopFolder(desktop) == NOERROR ) {
//
// determine full characteristics of name
//
wchar_t widename[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, a.c_str(), -1, widename, MAX_PATH);
unsigned long attr = 0;
int i;
TItemIDList* id = NULL;
desktop->ParseDisplayName(NULL, NULL, widename, i, id, attr);
if (id) {
//
// determine name from shell object
//
char sz[_MAX_PATH];
SHGetPathFromIDList(id, sz );
a = sz;
//
// clean up memory
//
Ole2::IMalloc *mem;
if (SHGetMalloc(mem) == NOERROR) {
mem->Free(id);
mem->Release();
}
}
//
// release resources
//
desktop->Release();
}
}
7/2/98 10:32:32 AM

Last Modified: 01-SEP-99