how to get file id in C#

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

how to get file id in C#

is there any kind of unique id that can be obtained for any file in a file
system?
 
Daniel said:
how to get file id in C#

is there any kind of unique id that can be obtained for any file in a file
system?
AFAIK, files in a file system are uniquely identified by their fully
qualified path, as you cannot have the same file name/extension multiple
times in a directory.
From within C#, when you instantiate the StreamReader or StreamWriter
classes, for example, you connect your instance to a unique entity on the
file system, either by hard coding the file name and path (as necessary) or
by allowing the user to select a file via a file open common dialog, then
using the selection as the argument for the constructor.
 
AFAIK, files in a file system are uniquely identified by their fully
qualified path, as you cannot have the same file name/extension multiple
times in a directory.

But you can have multiple paths to the same file because of hard links
and junction points. So two paths differing doesn't imply that they in
fact represent different files.

To check if two different file paths actually refer to the same file
you can open them both, call GetFileInformationByHandle and then
compare the BY_HANDLE_FILE_INFORMATION.dwVolumeSerialNumber,
..nFileIndexLow and .nFileIndexHigh values.


Mattias
 
Back
Top