我有以下代码:
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();
该应用程序钻入驱动器并找到驱动器中的所有文件/文件夹。我无法更改此路径,但由于它超过 260 个字符...如何解决此问题?