I want to delete a Directory and all its files and it has files/Directories with a very long path.
The file I'm trying to delete has a long path (longer than 260 characters).
How can I delete this file in spite of its length? I'm using the following code:
foreach (string archiveFolder in Archives)
{
try
{
DateTime creationTime = Directory.GetCreationTime(archiveFolder);
DateTime now = DateTime.Now;
DateTime passDate = creationTime.AddDays(numDaysBack);
if (passDate.CompareTo(now) < 0)
{
try
{
Directory.Delete(archiveFolder, true);
}
catch (Exception e)
{
}
//System.Console.WriteLine(creationTime);
}
}
catch (Exception e)
{
}
}