Best way to determine if two path reference to same file in Windows?

后端 未结 11 1639
生来不讨喜
生来不讨喜 2020-11-30 11:23

How would I compare 2 strings to determine if they refer to the same path in Win32 using C/C++?

While this will handle a lot of cases it misses some things:

11条回答
  •  独厮守ぢ
    2020-11-30 11:59

    If the files exist and you can deal with the potential race condition and performance hit from opening the files, an imperfect solution that should work on any platform is to open one file for writing by itself, close it, and then open it for writing again after opening the other file for writing. Since write access should only be allowed to be exclusive, if you were able to open the first file for writing the first time but not the second time then chances are you blocked your own request when you tried to open both files.

    (chances, of course, are also that some other part of the system has one of your files open)

提交回复
热议问题