File tree Expand file tree Collapse file tree 1 file changed +24
-5
lines changed
Expand file tree Collapse file tree 1 file changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -29,13 +29,32 @@ public static class DirectoryInfoExtension
2929 {
3030 public static void WalkFiles ( this DirectoryInfo dir , Action < string > onFile , int maxDepth = 4 )
3131 {
32- foreach ( var file in dir . GetFiles ( ) )
33- onFile ( file . FullName ) ;
32+ try
33+ {
34+ var options = new EnumerationOptions ( )
35+ {
36+ IgnoreInaccessible = true ,
37+ RecurseSubdirectories = false ,
38+ } ;
39+
40+ foreach ( var file in dir . GetFiles ( "*" , options ) )
41+ onFile ( file . FullName ) ;
3442
35- if ( maxDepth > 0 )
43+ if ( maxDepth > 0 )
44+ {
45+ foreach ( var subDir in dir . GetDirectories ( "*" , options ) )
46+ {
47+ if ( subDir . Name . StartsWith ( "." , StringComparison . Ordinal ) ||
48+ subDir . Name . Equals ( "node_modules" , StringComparison . OrdinalIgnoreCase ) )
49+ continue ;
50+
51+ WalkFiles ( subDir , onFile , maxDepth - 1 ) ;
52+ }
53+ }
54+ }
55+ catch
3656 {
37- foreach ( var subDir in dir . GetDirectories ( ) )
38- WalkFiles ( subDir , onFile , maxDepth - 1 ) ;
57+ // Ignore exceptions.
3958 }
4059 }
4160
You can’t perform that action at this time.
0 commit comments