Unicode files path
Checking if a file or folder exists with FileExists and DirectoryExists (VCL) will not work on Unicode files path, so here are the Unicode versions...
-
bool __fastcall FileExistsW(WideString WFilename)
-
{
-
WIN32_FIND_DATAW FindFileData;
-
HANDLE hFind;
-
-
hFind = FindFirstFileW(WFilename.c_bstr(), &FindFileData);
-
-
if (hFind != INVALID_HANDLE_VALUE) {
-
FindClose(hFind);
-
return true;
-
}
-
return false;
-
}
-
-
-
bool __fastcall DirectoryExistsW(WideString WFilename)
-
{
-
WIN32_FIND_DATAW FindFileData;
-
HANDLE hFind;
-
-
hFind = FindFirstFileW(WFilename.c_bstr(), &FindFileData);
-
-
if (hFind != INVALID_HANDLE_VALUE) {
-
FindClose(hFind);
-
if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) return true;
-
}
-
return false;
-
}
How about Unicode files passed at command line? WinMain function will return char*, but you need WideString (wchar_t *) to do your job with the file/path... Well there is fast way to handle that, just don't use the argument parameter passed at WinMain because obviously you will not get your path correctly, instead use the Unicode version of the GetCommandLine function: GetCommandLineW
Here is a sample:
-
int argCount=0;
-
LPWSTR* args;
-
args=CommandLineToArgvW(GetCommandLineW(),&argCount);
-
if (argCount>1)
-
{
-
AppParams=args[1];
-
AppParams=WideExcludeTrailingBackslash(AppParams);
-
-
}
related things:
Author: Raz | On January 27th, 2007 | C++ Builder, [ En ] | No Comments
Q: So what can I do next?
A: You can Buy me a Beer or Coffee. You can say Hi! or peek on the related stuff. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Spammers: Beware of » my Dog! «




