in reply to Re: Finding out whether two directories are the same
in thread Finding out whether two directories are the same

You can check the device and inode field of the results of stat for both directories, but that will only work for file systems that follow the idea the inventors originally had.

I guess this means "the usual file systems on Unix and Linux". Do you happen to know to what extent this is fulfilled for networked file systems on Windows?

You can readdir the directories and consider them to be the same if they contain the same files.
In my case, this would mean I would have to actually compare the content of the files, because even the sizes could be the same :-(
Thanks a lot for clarification.

Update: I just made a test on Windows, and the inode number indeed comes up as zero.
-- 
Ronald Fischer <ynnor@mm.st>
  • Comment on Re^2: Finding out whether two directories are the same

Replies are listed 'Best First'.
Re^3: Finding out whether two directories are the same
by Fletch (Bishop) on Aug 28, 2008 at 13:04 UTC

    You might take a gander at how rsync for inspiration. Or maybe use rsync -n and see if it thinks there's a difference.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Testing for identical content (whether using rsync or something else) will not give you a 100% sure answer. Even if the content is the same, the directories do not have to, for instance:
      $ cp -a dir1 dir2
      will create a second directory with identical content, but dir1 and dir2 are different. You'd have to look at inode change time to see a difference, but even then, it's not a garantee.

      OTOH, even if you think the content is different, the directories may be the same. If the directories are the same, you'll be looking at the same directory twice, but since you cannot garantee you'll be looking twice at the same time, the directory, or any of its files inside it, may have changed between your two inspections.

      Having said that, I don't think there's solution that will always work anywhere. But usually you will know a bit of the environment. If you know your filesystems are local, and no device is mounted twice, checking inode and device number will do. If you know the directories to be tested aren't being modified while you make your check, checking for content may work.

      As far I see, rsync does not run on native Windows (Cygwin is not an option here) :-(

      -- 
      Ronald Fischer <ynnor@mm.st>