c - FindFirstFile 和 Junctions

标签 c windows winapi

我用它来获取目录 foo 的内容:FindFirstFile(L"foo\\*", &findData)。当 foo 是一个常规目录时,它工作得很好。但是,当 foo 是指向另一个目录(使用 mklink/j foo C:\gah 创建)的连接时,FindFirstFile 失败。

文档是这样说的:“如果路径指向符号链接(symbolic link),则 WIN32_FIND_DATA 缓冲区包含有关符号链接(symbolic link)的信息,而不是目标。”但是当我运行调试器时,我只得到一个 INVALID_HANDLE_VALUE 并且 findData 保持不变。

那么,我该如何解决这个问题?

最佳答案

Raymond Chen 有一个 answer给你。

Functions like GetFileAttributes and FindFirstFile, when asked to provide information about a symbolic link, returns information about the link itself and not the link destination. If you use the FindFirstFile function, you can tell that you have a symbolic link because the file attributes will have the FILE_ATTRIBUTES_REPARSE_POINT flag set, and the dwReserved0 member will contain the special value IO_REPARSE_TAG_SYMLINK.

Okay, great, so now I know I have a symbolic link, but what if I want information about the link target? For example, I want to know the size of the link target, its last-modified time, and its name.

To do this, you open the symbolic link. The I/O manager dereferences the symbolic link and gives you a handle to the link destination. You can then call functions like GetFileSize, GetFileInformationByHandleEx, or GetFinalPathNameByHandle to obtain information about the symbolic link target.

关于c - FindFirstFile 和 Junctions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6797295/

相关文章:

winapi - 如何让 Inno Setup 解压单个文件?

c++ - GtkTextBuffer 的问题,令人困惑的运行时错误。需要帮忙?

c - 如何在 C 中打印两个相邻的一维数组

python - 从 Python 中查找系统硬盘驱动器?

html - CSS 在 Windows 上的显示与 Mac 不同

c++ - 编译器如何决定函数在导入表中的顺序

winapi - 在 CDialog 中显示大小控制?

c - 汇编语言-工作原理

c - 为什么 "i =++i;"和 "i =++i + 2;"是未定义的行为?

css - Windows 上的 Chrome 和 Firefox 上的字体基线被破坏