Detecting if a directory is a junction in Delphi

前端 未结 2 1253
难免孤独
难免孤独 2021-02-13 02:08

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

2条回答
  •  花落未央
    2021-02-13 02:27

    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;
    

提交回复
热议问题