【发布时间】:2013-09-19 12:22:58
【问题描述】:
- prgchDirPath 是字符指针。但预期的是 LPCWSTR。 如何更改?
-
prgchDirPath 是目录路径。 文件不存在。 但我想确定目录/路径是否存在。 下面的 API 可以帮助我吗?如果是,怎么做?
unsigned char IsFilePathCorrect(char* prgchDirPath) { WIN32_FIND_DATA FindFileData; HANDLE handle; int found=0; //1. prgchDirPath is char pointer. But expected is LPCWSTR. //How to change this? //2. prgchDirPath is a directory path. File is not existed. //But I want to make sure if directory/path exists or not. //Can the API below helps me? if yes, how? handle = FindFirstFile(prgchDirPath, &FindFileData); if(handle != INVALID_HANDLE_VALUE) found = 1; if(found) { FindClose(handle); } return found; }
我想检查目录路径是否存在。请提供一个示例代码。谢谢。
【问题讨论】:
-
尝试调用 FindFirstFile 的窄版
FindFirstFileA,并使用结构的窄版WIN32_FIND_DATAA -
@WhozCraig 感谢分配。我现在可以直接传递 char 指针。但问题是,我将 "C:\\" 和 '&FindFileData' 传递给了这个 API,它给出了返回码 0xFFFFFFFF,这意味着没有找到,对吧?路径 C:\ 存在于我的本地驱动器中。
-
这意味着没有找到,因为那不是目录,它只是一个路径。你还没有完成。试试
"C:\\." -
@WhozCraig 你说得对,我创建了一个名为 'xx' 的目录,并将路径指定为
"C:\\xx"并且它有效。但是我也试过给"C:\\.",但是没用。 -
如果要检查驱动器号是否存在,可以使用
GetLogicalDrives。
标签: c file winapi widechar lpcwstr