Search code examples
c#.netwindows-10

Cannot set creation time when a file is on a removable disk


I try to set Creation, Write and Access time for all files in a directory. And that works if file is on local machine. But when I try to do it for directory on a removable disk, I get an exception:

System.IO.IOException: 'The parameter is incorrect. : '*path*'

I really don't know why it happens, but:

  • the path is correct
  • BitLocker is turned off
  • files don't have a read-only attribute
static void Main(string[] args)
{
    var files = new DirectoryInfo(args[0]).GetFiles();

    foreach (var file in files)
    {
        File.SetCreationTime(file.FullName, new DateTime(1970, 1, 1));
        File.SetLastAccessTime(file.FullName, new DateTime(1970, 1, 1));
        File.SetLastWriteTime(file.FullName, new DateTime(1970, 1, 1));
    }
}

I'll be grateful for your help.


Solution

  • The exception is thrown because a filesystem on my flash drive is FAT. And the FAT file system counts dates from 1/1/1980.