Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do 2 different filenames refer to the same file?

Status
Not open for further replies.

MKuiper

Programmer
Jan 29, 2002
364
NL
Hi,

Does anybody know: How to find out whether 2 different filenames (like "\\computer\share\dir\file.ext" and "C:\dir\file.ext") refer to the same file or not?

Am I overlooking an API like
BOOL fIsSameFile ( LPSTR lpFileName1, LPSTR lpFileName2 )
??

Thanks Marcel
 
I've got it already. For those who are interested:

call GetFileInformationByHandle for both of the filenames.
The names refer to the same file if the following members of the two BY_HANDLE_FILE_INFORMATION structs match:
- dwVolumeSerialNumber
- nFileIndexHigh
- nFileIndexLow Marcel
 
You could explore the WNetGetConnection api function... using it you can convert a mapped drive letter path to the equivalent UNC path, then see if that matches the other path you have.
 
wgcs,

thank you for the suggestion.
My routine however, works fine now.
It will not be easy to do it your way.
You must keep track yourself of:

- environment strings, like %TEMP%\file.ext
- long and short names, like C:\Program Files and C:\progra~1
- If a file has no extension, a file name ending with a period is the same as a filename without a period, C:\File. == C:\File

The only way my routine fails, and yours succeeds, is when the file does not exist. But I'm going to use this for a file-handler, which is going to be I-O server for other programs. If a request comes to open a file I need to know if my program has it already open or not. And when it doesn't exist, it will not be opened, too. So in practice my routine works fine.

Marcel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top