我有以下代碼:PathTooLongException在C#代碼
public static void Serialize()
{
List<string> dirs = FileHelper.GetFilesRecursive(fileDirectoryPath);
List<string> dirFiles = new List<string>();
foreach (string p in dirs)
{
string path = p;
string lastAccessTime = File.GetLastAccessTime(path).ToString();
bool DirFile = File.Exists(path);
FileInfo fInf = new FileInfo(path);
long lengthInk = fInf.Length/1024;
DateTime lastWriteTime = File.GetLastWriteTime(p);
dirFiles.Add(p + "|" + lastAccessTime.ToString() + "|" + DirFile.ToString() + "|" + lastWriteTime.ToString() + "|" + lengthInk.ToString() + " kb");
}
我不斷撞擊與以下行PathTooLongException錯誤:
string lastAccessTime = File.GetLastAccessTime(path).ToString();
應用鑽入一個驅動器,並找到所有文件/文件夾w /在驅動器中。我無法改變這條道路,但因爲它超過了260個字符......如何解決這個問題?
use windows api [http://galratner.com/blogs/net/archive/2011/02/13/getting-around-pathtoolongexception-on-file-move-with-windows-native-api.aspx ](http://galratner.com/blogs/net/archive/2011/02/13/getting-around-pathtoolongexception-on-file-move-with-windows-native-api.aspx) – julian 2012-02-06 14:53:35
我自己的和其他答案[here](http://stackoverflow.com/a/29605805/589059)建議您可以使用一些包裝庫來處理長路徑。 – rkagerer 2015-04-13 13:32:07
可能重複的[如何避免System.IO.PathTooLongException?](http://stackoverflow.com/questions/530109/how-to-avoid-system-io-pathtoolongexception) – Deantwo 2017-03-14 12:42:49