检测目录是否是Delphi中的连接点 [英] Detecting if a directory is a junction in Delphi
问题描述
我一直在谷歌搜索这个我可能会有一些大脑云,因为它不工作。
我需要检测文件夹是否是一个连接所以我的递归文件搜索并不会无止境循环。
我可以使用一个简单的函数,如
IsJunction(attr:dword):boolean;
其中attr是来自TWin32FindData的 dwFileAttributes
/ p>
我似乎无法让它工作。谢谢!
dwFileAttributes
TWin32FindData
没有这些信息,你必须看看 dwReserved0
字段。请参阅文档。
函数IsJunction(const FileName:string):Boolean;
// IO_REPARSE_TAG_MOUNT_POINT = $ A0000003;
var
FindHandle:THandle;
FindData:TWin32FindData;
begin
结果:= False;
FindHandle:= FindFirstFile(PChar(FileName),FindData);
if FindHandle<> INVALID_HANDLE_VALUE然后开始
结果:=(Bool(FindData.dwFileAttributes和FILE_ATTRIBUTE_REPARSE_POINT))
和Bool(FindData.dwReserved0和$ 80000000)// MS位
和Bool(FindData.dwReserved0和$ 20000000) //名称替代位
和(LoWord(FindData.dwReserved0)= 3); // mount point value
winapi.windows.FindClose(FindHandle);
end else
RaiseLastOSError;
结束
I've been Google searching this I may be having some brain clouds because it just isn't working.
I need to detect if a folder is a junction so my recursive file search doesn't run off into an endless loop.
I could use a simple function like
IsJunction(attr: dword): boolean;
where attr is dwFileAttributes
from TWin32FindData;
I just can't seem to get it to work. Thanks!
dwFileAttributes
of TWin32FindData
does not have that information, you have to look to the dwReserved0
field. See documentation.
function IsJunction(const FileName: string): Boolean;
// IO_REPARSE_TAG_MOUNT_POINT = $A0000003;
var
FindHandle: THandle;
FindData: TWin32FindData;
begin
Result := False;
FindHandle := FindFirstFile(PChar(FileName), FindData);
if FindHandle <> INVALID_HANDLE_VALUE then begin
Result := (Bool(FindData.dwFileAttributes and FILE_ATTRIBUTE_REPARSE_POINT))
and Bool(FindData.dwReserved0 and $80000000) // MS bit
and Bool(FindData.dwReserved0 and $20000000) // name surrogate bit
and (LoWord(FindData.dwReserved0) = 3); // mount point value
winapi.windows.FindClose(FindHandle);
end else
RaiseLastOSError;
end;
这篇关于检测目录是否是Delphi中的连接点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!