0

I have a shared folder (TestFolder) on my Windows machine.

  • Full path to the folder: D:/TestFolder
  • Machine name: anil-win10
  • Machine IP: 10.130.63.10

Case 1: I have my C++ application running on the other machine and it contains a list of network paths. I can add followings two paths to the list.

  • \\anil-win10\TestFolder
  • \\10.130.63.10\TestFolder

I want to know if the list has duplicates and remove the duplicates.

How can I get to know using C/C++ Win32 APIs?

Case 2: My C++ application is running on the same machine.

I can add same shared folder via.

  • \\anil-win10\TestFolder
  • \\10.130.63.10\TestFolder
  • D:/TestFolder

Actually, all 3 paths are pointing to the same location, here also I want to remove the duplicate paths. Looking for same C/C++ Win32 solution.

Anil8753
  • 2,663
  • 4
  • 29
  • 40
  • Not the only way to create an alias, also mapped drive letter, SUBST drives, symbolic link. [Look here](https://stackoverflow.com/questions/10680379/does-folders-in-windows-have-ids-or-guids). Beware non-NTFS file systems. – Hans Passant Apr 14 '18 at 10:24

1 Answers1

0

Based on Hans suggestion, here is the solution.

#include "windows.h"

long long GetFolderSystemId(const WCHAR* path)
{
    ULONG id = 0;

    HANDLE hFile = CreateFileW(path,
        GENERIC_READ,
        FILE_SHARE_READ,
        0,
        OPEN_EXISTING,
        FILE_FLAG_BACKUP_SEMANTICS,
        NULL);

    if (INVALID_HANDLE_VALUE != hFile)
    {
        BY_HANDLE_FILE_INFORMATION fileInfo;
        BOOL result = GetFileInformationByHandle(hFile, &fileInfo);

        if (result)
        {
            id = ((ULONG)(fileInfo.nFileIndexHigh << 32) | (ULONG)fileInfo.nFileIndexLow);
        }

       CloseHandle(hFile);
    }
    return id;
}

int main()
{

    long long id1 = GetFolderSystemId(L"\\\\anikumar-win7\\Shared\\Archives\\Business Jobs_");
    long long id2 = GetFolderSystemId(L"\\\\10.110.196.28\\Shared\\Archives\\Business Jobs_");

    if (id1 == id2)
        std::cout << "location are same" << std::endl;
    else
        std::cout << "location are not same" << std::endl;

    return 0;
}
Anil8753
  • 2,663
  • 4
  • 29
  • 40