我用它来获取目录 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
andFindFirstFile
, when asked to provide information about a symbolic link, returns information about the link itself and not the link destination. If you use theFindFirstFile
function, you can tell that you have a symbolic link because the file attributes will have theFILE_ATTRIBUTES_REPARSE_POINT
flag set, and thedwReserved0
member will contain the special valueIO_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
, orGetFinalPathNameByHandle
to obtain information about the symbolic link target.
关于c - FindFirstFile 和 Junctions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6797295/