An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
When you copy a file, the behavior of creation and modified timestamps depends on the API used and the underlying file system. On Windows NTFS, when you copy a file using typical APIs like File.Copy, the new file gets a new creation time (the moment the copy is created), but the last write time (modified time) is usually preserved from the source file. That is why you see the creation time change but the modified time remain the same. Creation time represents when that specific file entry was created in that filesystem location, not when the content was originally created.
If your goal is to verify that the copy operation preserved the original creation time, you need to be aware that File.Copy does not guarantee preservation of creation time. If you require it to match, you must explicitly set it after copying:
File.Copy(inputPath, outputPath, overwrite: true);
var inputCreation = File.GetCreationTimeUtc(inputPath);
File.SetCreationTimeUtc(outputPath, inputCreation);
To implement a function VerifySameCreationTime, you should compare the UTC timestamps and optionally allow a tolerance to account for filesystem timestamp resolution differences. Different filesystems have different timestamp precision. NTFS supports 100-nanosecond resolution, but other filesystems (for example FAT) have 2-second resolution for certain timestamps. Network shares and cross-platform copies can also introduce truncation.
One potential implementation would be:
public static bool VerifySameCreationTime(string inputPath, string outputPath, TimeSpan? tolerance = null)
{
var inputCreation = File.GetCreationTimeUtc(inputPath);
var outputCreation = File.GetCreationTimeUtc(outputPath);
var allowedDrift = tolerance ?? TimeSpan.Zero;
return Math.Abs((outputCreation - inputCreation).Ticks) <= allowedDrift.Ticks;
}
Whether you need tolerance depends on your environment. If both files are on NTFS on the same machine and you explicitly set the creation time, you usually do not need tolerance. If files may reside on FAT, SMB shares, Linux filesystems, or cloud-mounted storage, you should allow tolerance.
How much tolerance to use depends on the lowest precision filesystem you expect. If FAT is involved, up to 2 seconds is reasonable. If only NTFS is involved, you can often use zero or a very small tolerance like a few milliseconds. If you do not control the storage backend, I'd consider 1–2 seconds to be a pragmatic safe value.
The snippet ChatGPT suggested:
var tolerance = TimeSpan.FromSeconds(2);
var outputIsNewer = outputCreation - inputCreation > tolerance;
is not sufficient to verify “same creation time” because it only checks whether the output is significantly newer. It does not check the absolute difference in both directions.
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin