@@ -34,6 +34,11 @@ internal sealed class Program
3434 /// </summary>
3535 private static Int64 totalMatches ;
3636
37+ /// <summary>
38+ /// The total number of bytes the matching file consume.
39+ /// </summary>
40+ private static Int64 totalMatchesSize ;
41+
3742 /// <summary>
3843 /// The total number of files looked at.
3944 /// </summary>
@@ -44,6 +49,11 @@ internal sealed class Program
4449 /// </summary>
4550 private static Int64 totalDirectories ;
4651
52+ /// <summary>
53+ /// The total number of bytes the files looked at consume.
54+ /// </summary>
55+ private static Int64 totalSize ;
56+
4757 /// <summary>
4858 /// The collection to hold found strings so they can be printed in batch mode.
4959 /// </summary>
@@ -72,8 +82,10 @@ internal static Int32 Main(String[] args)
7282 Boolean parsed = Options . Parse ( args ) ;
7383
7484 totalMatches = 0 ;
85+ totalMatchesSize = 0 ;
7586 totalFiles = 0 ;
7687 totalDirectories = 0 ;
88+ totalSize = 0 ;
7789
7890 if ( parsed )
7991 {
@@ -96,9 +108,11 @@ internal static Int32 Main(String[] args)
96108 Console . WriteLine ( Constants . TotalTimeFmt , timer . ElapsedMilliseconds . ToString ( "N0" , CultureInfo . CurrentCulture ) ) ;
97109 Console . WriteLine ( Constants . TotalFilesFmt , totalFiles . ToString ( "N0" , CultureInfo . CurrentCulture ) ) ;
98110 Console . WriteLine ( Constants . TotalDirectoriesFmt , totalDirectories . ToString ( "N0" , CultureInfo . CurrentCulture ) ) ;
111+ Console . WriteLine ( Constants . TotalSizeFmt , totalSize . ToString ( "N0" , CultureInfo . CurrentCulture ) ) ;
99112 Console . WriteLine ( Constants . TotalMatchesFmt , totalMatches . ToString ( "N0" , CultureInfo . CurrentCulture ) ) ;
113+ Console . WriteLine ( Constants . TotalMatchesSizeFmt , totalMatchesSize . ToString ( "N0" , CultureInfo . CurrentCulture ) ) ;
100114 }
101- }
115+ }
102116 else
103117 {
104118 returnValue = 1 ;
@@ -256,7 +270,15 @@ private static void QueueConsoleWriteLine(String line)
256270 /// </remarks>
257271 static private void RecurseFiles ( String directory )
258272 {
259- String lookUpdirectory = "\\ \\ ?\\ " + directory + "\\ *" ;
273+ String lookUpdirectory = String . Empty ;
274+ if ( directory . StartsWith ( @"\\" , StringComparison . OrdinalIgnoreCase ) )
275+ {
276+ lookUpdirectory += directory . Replace ( @"\\" , @"\\?\UNC\" ) + "\\ *" ;
277+ }
278+ else
279+ {
280+ lookUpdirectory = "\\ \\ ?\\ " + directory + "\\ *" ;
281+ }
260282 NativeMethods . WIN32_FIND_DATA w32FindData ;
261283
262284 using ( SafeFindFileHandle fileHandle = NativeMethods . FindFirstFileEx ( lookUpdirectory ,
@@ -297,9 +319,12 @@ static private void RecurseFiles(String directory)
297319 }
298320 else
299321 {
300- // It's a file so look at it.
322+ // It's a file so look at it.
301323 Interlocked . Increment ( ref totalFiles ) ;
302324
325+ Int64 fileSize = w32FindData . nFileSizeLow + ( ( Int64 ) w32FindData . nFileSizeHigh << 32 ) ;
326+ Interlocked . Add ( ref totalSize , fileSize ) ;
327+
303328 String fullFile = directory ;
304329 if ( ! directory . EndsWith ( "\\ " , StringComparison . OrdinalIgnoreCase ) )
305330 {
@@ -317,6 +342,7 @@ static private void RecurseFiles(String directory)
317342 if ( IsNameMatch ( matchName ) )
318343 {
319344 Interlocked . Increment ( ref totalMatches ) ;
345+ Interlocked . Add ( ref totalMatchesSize , fileSize ) ;
320346 QueueConsoleWriteLine ( fullFile ) ;
321347 }
322348 }
0 commit comments