Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to find a way to uniquely identify a file on windows. In unix, I'd just call stat() on a filename and use the device and inode number pair. However, that doesn't seem to work at all in Windows, so I'm at a loss. What can I do?

Replies are listed 'Best First'.
Re: Uniquely identifying files on windows
by ikegami (Patriarch) on Dec 29, 2005 at 20:04 UTC

    NTFS supports Reparse Points -- MS's name for hard links -- so it's possible to have two paths refer to the same file. There is a function you can call to get the GUID of the Reparse Point. Judging by the name, this should be unique across all devices and machines.

    On a given FAT device, the path is the unique identifier (once "." and ".." are properly removed). However, it is tricky to determine whether two devices are the same (in part or in whole). Given

    net use z: \\127.0.0.1\c$ net use y: \\127.0.0.1\share_c net use x: \\10.0.0.5\c$ net use w: \\tribble05\c$ subst v: c:\ net use u: \\127.0.0.1\c$\dir net use t: \\127.0.0.1\share_dir subst s: c:\dir
    the following could all refer to the same file:
    c:\dir\file z:\dir\file y:\dir\file w:\dir\file v:\dir\file x:\dir\file u:\file t:\file s:\file

    It's even trickier once virtual drivers and shares on non-Windows machine come into play.

Re: Uniquely identifying files on windows
by holli (Abbot) on Dec 29, 2005 at 19:21 UTC
    You can calculate a checksum, e.g. using the Digest::MD5 module.


    holli, /regexed monk/
        Yes, but there is no such thing like an "ununique" file under windows (except you can have hard links, but I have never seen a real life usage of that).


        holli, /regexed monk/