Error: File Path is Too Long

后端 未结 4 1076
没有蜡笔的小新
没有蜡笔的小新 2021-01-18 17:57

i am trying to use the various file functions in C# like File.GetLastWriteTime, copy command on the file placed at the path greater than maximum allowed path on

4条回答
  •  無奈伤痛
    2021-01-18 18:19

    Here's a solution for at least the copying portion of your request (thank you pinvoke.net):

    [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
    static extern bool CopyFile(string lpExistingFileName, string lpNewFileName, bool bFailIfExists);
    

    And then to actually copy your file:

    // Don't forget the '\\?\' for long paths
    string reallyLongPath = @"\\?\d:\abc\bcd\cd\cdc\dc\..........";
    string destination = @"C:\some\other\path\filename.txt";
    CopyFile(reallyLongPath , destination, false);
    

提交回复
热议问题