問題描述
如何比較 2 個字符串以確定它們是否使用 C/C++ 引用 Win32 中的相同路徑?
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:
_tcsicmp(szPath1, szPath2) == 0
例如:
正斜杠/反斜杠
forward slashes / backslashes
相對/絕對路徑.
標題已更改以匹配現有的 C# 問題.
Title changed to match an existing C# question.
推薦答案
用 CreateFile
打開兩個文件,為兩者調用 GetFileInformationByHandle
,并比較 dwVolumeSerialNumber代碼>、<代碼>nFileIndexLow
、nFileIndexHigh
.如果三個都相等,它們都指向同一個文件:
Open both files with CreateFile
, call GetFileInformationByHandle
for both, and compare dwVolumeSerialNumber
, nFileIndexLow
, nFileIndexHigh
. If all three are equal they both point to the same file:
GetFileInformationByHandle
函數一個>
BY_HANDLE_FILE_INFORMATION
結構
這篇關于確定兩個路徑是否引用 Windows 中同一個文件的最佳方法?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!