Skip to content

Commit ab49072

Browse files
author
Dan Lewi Harkestad
committed
Fixed path too long problem.
In solutions containing a node_modules folder somewhere, there was a very good chance that you would get a PathTooLongException since the fully qualified name was larger than 260 chars. This change determines last write time in a way that doesn't throw this exception.
1 parent 0cb1c22 commit ab49072

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
using System;
2-
using System.IO;
1+
using System.IO;
2+
using System.Linq;
33

44
public static class DirectoryDateFinder
55
{
66
public static long GetLastDirectoryWrite(string path)
77
{
8-
var lastHigh = DateTime.MinValue;
9-
foreach (var file in Directory.EnumerateDirectories(path, "*.*", SearchOption.AllDirectories))
10-
{
11-
var lastWriteTime = File.GetLastWriteTime(file);
12-
if (lastWriteTime > lastHigh)
13-
{
14-
lastHigh = lastWriteTime;
15-
}
16-
}
17-
return lastHigh.Ticks;
8+
return new DirectoryInfo(path)
9+
.GetDirectories("*.*", SearchOption.AllDirectories)
10+
.Select(d => d.LastWriteTimeUtc)
11+
.DefaultIfEmpty()
12+
.Max()
13+
.Ticks;
1814
}
1915
}

0 commit comments

Comments
 (0)