如何通过Windows原生API获取目录信息?
我可以使用以下代码获取文件的创建日期、文件大小等:
// Error handling removed for brevity
HANDLE hFile = CreateFile(path, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
LARGE_INTEGER fileSize;
GetFileSizeEx(hFile, &fileSize);
FILE_BASIC_INFO fileInfo);
GetFileInformationByHandle(hFile, FileBasicInfo, fileInfo, sizeof(fileInfo));
但是当针对目录调用时,所有值都设置为零 - 如何获取目录信息?
谢谢
I can get the created date, file size etc for a file using the following code:
// Error handling removed for brevity
HANDLE hFile = CreateFile(path, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
LARGE_INTEGER fileSize;
GetFileSizeEx(hFile, &fileSize);
FILE_BASIC_INFO fileInfo);
GetFileInformationByHandle(hFile, FileBasicInfo, fileInfo, sizeof(fileInfo));
But when called against a directory, all values are set to zero - how do I get directory info?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦您必须传递此标志才能获取目录的有效句柄,我就遇到了类似的情况。来自 MSDN 文档。
试试这个
FILE_FLAG_BACKUP_SEMANTICS
|您必须设置此标志才能获取目录的句柄。可以将目录句柄而不是文件句柄传递给某些函数。有关详细信息,请参阅备注部分。I ran into something like this once you have to pass this flag to get a valid handle for a directory. From the MSDN documentation.
try this
FILE_FLAG_BACKUP_SEMANTICS
| You must set this flag to obtain a handle to a directory. A directory handle can be passed to some functions instead of a file handle. For more information, see the Remarks section.