Is it possible that multiple files can be created at the exact same time? Well obviously it is possible in some cases (I don't know those cases) when I call FileInfo
classes CreationTimeUtc()
method, it gives me exactly same time string. I differentiate the files under the same folder from each other by looking at their creation time, but since sometimes the creation times are same it ruins my approach. In that case I need a proper identifier for files to identify a file even if it's renamed or changed. I don't know what kind of an identifier i can use for this purpose. Any help would be appreciated. I am using C# .net 4.5
Asked
Active
Viewed 134 times
0

Raman
- 1,336
- 10
- 13

Tolga Evcimen
- 7,112
- 11
- 58
- 91
-
1Yes it is possible, not least because you can programatically set the creation date/time of a file. – Matthew Watson Apr 10 '13 at 09:43
-
Could you give us some more background information? In general, identifying files by any date/time sounds like a bad practice to me. – Mels Apr 10 '13 at 10:08
2 Answers
1
To identify files, you may want to compute a checksum, so the content is identified, not the name or date or location. Have a look here.
-
The OP says the files should be tracked across renames and _changes_. Any change would invalidate the hash. – Mels Apr 10 '13 at 10:06
0
I solved the problem by using GetFileInformationByHandle() method as follows :
private static string GetFilePointer(FileInfo fi)
{
var fs = fi.OpenRead();
var ofi = new BY_HANDLE_FILE_INFORMATION();
ulong fileIndex = 0;
if (GetFileInformationByHandle((IntPtr)fs.Handle, out ofi))
{
fileIndex = ((ulong)ofi.FileIndexHigh << 32) + (ulong)ofi.FileIndexLow;
}
fs.Close();
return fileIndex.ToString();
}
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool GetFileInformationByHandle(IntPtr hFile, out BY_HANDLE_FILE_INFORMATION lpFileInformation);
[StructLayout(LayoutKind.Sequential)]
struct BY_HANDLE_FILE_INFORMATION
{
public uint FileAttributes;
public FILETIME CreationTime;
public FILETIME LastAccessTime;
public FILETIME LastWriteTime;
public uint VolumeSerialNumber;
public uint FileSizeHigh;
public uint FileSizeLow;
public uint NumberOfLinks;
public uint FileIndexHigh;
public uint FileIndexLow;
}
looks like a really neat way of having a file identifier on ntfs file systems, renames, content changes or moves doesn't affect it.

Tolga Evcimen
- 7,112
- 11
- 58
- 91