PathTooLongException in C# code

前端 未结 4 1703
攒了一身酷
攒了一身酷 2020-12-07 04:38

i have the following code:

 public static void Serialize()
    {

        List dirs = FileHelper.GetFilesRecursive(fileDirectoryPath);
                 


        
4条回答
  •  一整个雨季
    2020-12-07 04:55

    The GetLastAccessTime() call, with a full path can exceed the internal limit (which is OS-version specific, but typically 260 characters) on the maximum length for a fully qualified file path.

    One way to avoid this, is to use Directory.SetCurrentDirectory() to change the current system directory and then call GetLastAccessTime() with only a relative path. Just make sure you change your current directory back to what you started from to avoid unexpected issues.

提交回复
热议问题