I can count all the files in a folder and sub-folders, the folders themselves are not counted.
(gci -Path *Fill_in_path_here* -Recurse -File | where Name -like "*STB*").Count
However, powershell is too slow for the amount of files (up to 700k). I read that cmd is faster in executing this kind of task.
Unfortunately I have no knowledge of cmd code at all. In the example above I am counting all the files with STB
in the file name.
That is what I would like to do in cmd as well.
Any help is appreciated.
One of the fastest ways to do it in cmd
command line or batch file could be
dir "x:\some\where\*stb*" /s /b /a-d | find /c /v ""
Just a recursive ( /s
) dir
command to list all files (no folders /ad
) in bare format ( /b
), with all the output piped to find
command that will count ( /c
) the number of non empty lines ( /v ""
)
But, in any case, you will need to enumerate the files and it requires time.
edited to adapt to comments, BUT
note The approach below does not work for this case because, at least in windows 10, the space padding in the summary lines of the dir
command is set to five positions. File counts greater than 99999 are not correctly padded, so the sort /r
output is not correct.
As pointed by Ben Personick, the dir
command also outputs the number of files and we can retrieve this information:
@echo off
setlocal enableextensions disabledelayedexpansion
rem Configure where and what to search
set "search=x:\some\where\*stb*"
rem Retrieve the number of files
set "numFiles=0"
for /f %%a in ('
dir "%search%" /s /a-d /w 2^>nul %= get the list of the files =%
^| findstr /r /c:"^ *[1-9]" %= retrieve only summary lines =%
^| sort /r 2^>nul %= reverse sort, greater line first =%
^| cmd /e /v /c"set /p .=&&echo(!.!" %= retrieve only first line =%
') do set "numFiles=%%a"
echo File(s) found: %numFiles%
The basic idea is use a serie of piped commands to handle different parts of data retrieval:
dir
command to generate the list of files ( /w
is included just to generate less lines). findstr
is used to retrieve only that lines starting with spaces (the header/summary lines) and a number greater than 0 (file count summary lines, as we are using /ad
the directory count summary lines will have a value of 0). set /p
command in a separate cmd
instance. As the full sequence is wrapped in a for /f
and it has a performance problem when retrieving long lists from command execution, we will try to retrieve as little as possible. The for /f
will tokenize the retrieved line, get the first token (number of files) and set the variable used to hold the data (variable has been initialized, it is possible that no file could be found).
You can speed up things with PowerShell, if you include the filter
directly within the command
instead of filtering the result set
of the command which is way bigger than a pre filtered one.
Try this:
(Get-ChildItem -Path "Fill_in_path_here" -Recurse -File -Include "*STB*").Count
Theo's helpful answer based on direct use of .NET ( [System.IO.Directory]::EnumerateFiles()
) is the fastest option (in my tests; YMMV - see the benchmark code below [1] ).
Its limitations in the .NET Framework (FullCLR) - on which Windows PowerShell is built - are:
An exception is thrown when an inaccessible directory is encountered (due to lack of permissions). You can catch the exception, but you cannot continue the enumeration ; that is, you cannot robustly enumerate all items that you can access while ignoring those that you cannot.
Hidden items are invariably included.
With recursive enumeration, symlinks / junctions to directories are invariably followed.
By contrast, the cross-platform .NET Core framework, since v2.1 - on which PowerShell Core is built - offers ways around these limitations , via the EnumerationOptions
options - see this answer for an example.
Note that you can also perform enumeration via the related [System.IO.DirectoryInfo]
type, which - similar to Get-ChildItem
- returns rich objects rather than mere path strings, allowing for much for versatile processing; eg, to get an array of all file sizes (property .Length
, implicitly applied to each file object):
([System.IO.DirectoryInfo] $somePath).EnumerateFiles('*STB*', 'AllDirectories').Length
A native PowerShell solution that addresses these limitations and is still reasonably fast is to use Get-ChildItem
with the -Filter
parameter .
(Get-ChildItem -LiteralPath $somePath -Filter *STB* -Recurse -File).Count
Hidden items are excluded by default; add -Force
to include them.
To ignore permission problems, add -ErrorAction SilentlyContinue
or -ErrorAction Ignore
; the advantage of SilentlyContinue
is that you can later inspect the $Error
collection to determine the specific errors that occurred, so as to ensure that the errors truly only stem from permission problems.
$env:USERPROFILE\\Cookies
. In Windows PowerShell , Get-ChildItem -Recurse
invariably follows symlinks / junctions to directories, unfortunately; more sensibly, PowerShell Core by default does not , and offers opt-in via -FollowSymlink
.
Like the [System.IO.DirectoryInfo]
-based solution, Get-ChildItem
outputs rich objects ( [System.IO.FileInfo]
/ [System.IO.DirectoryInfo]
) describing each enumerated file-system item, allowing for versatile processing.
Note that while you can also pass wildcard arguments to -Path
(the implied first positional parameter) and -Include
(as in TobyU's answer ), it is only -Filter
that provides significant speed improvements , due to filtering at the source (the filesystem driver), so that PowerShell only receives the already-filtered results; by contrast, -Path
/ -Include
must first enumerate everything and match against the wildcard pattern afterwards . [2]
Caveats re -Filter
use :
*[0-9]
) and it has legacy quirks - see this answer . -Include
supports multiple (as an array). That said, -Filter
processes wildcards the same way as cmd.exe
's dir
.
Finally, for the sake of completeness, you can adapt MC ND's helpful answer based on cmd.exe
's dir
command for use in PowerShell, which simplifies matters:
(cmd /c dir /s /b /a-d "$somePath/*STB*").Count
PowerShell captures an external program's stdout output as an array of lines, whose element count you can simply query with the .Count
(or .Length
) property.
That said, this may or may not be faster than PowerShell's own Get-ChildItem -Filter
, depending on the filtering scenario; also note that dir /s
can only ever return path strings , whereas Get-ChildItem
returns rich objects whose properties you can query.
Caveats re dir
use :
/ad
excludes directories, ie, only reports files, but then also includes hidden files, which dir
doesn't do by default.
dir /s
invariably descends into hidden directories too during the recursive enumeration; an /a
(attribute-based) filter is only applied to the leaf items of the enumeration (only to files in this case).
dir /s
invariably follows symlinks / junctions to other directories (assuming it has the requisite permissions - see next point).
dir /s
quietly ignores directories or symlinks / junctions to directories if it cannot enumerate their contents due to lack of permissions - while this is helpful in the specific case of the aforementioned hidden system junctions (you can find them all with cmd /c dir C:\\ /s /ashl
), it can cause you to miss the content of directories that you do want to enumerate, but can't for true lack of permissions, because dir /s
will give no indication that such content may even exist (if you directly target an inaccessible directory, you get a somewhat misleading File Not Found
error message, and the exit code is set to 1
).
Performance comparison:
The following tests compare pure enumeration performance without filtering , for simplicity, using a sizable directory tree assumed to be present on all systems, c:\\windows\\winsxs
; that said, it's easy to adapt the tests to also compare filtering performance.
The tests are run from PowerShell, which means that some overhead is introduced by creating a child process for cmd.exe
in order to invoke dir /s
, though (a) that overhead should be relatively low and (b) the larger point is that staying in the realm of PowerShell is well worthwhile, given its vastly superior capabilities compared to cmd.exe
.
The tests use function Time-Command
, which can be downloaded from this Gist , which averages 10 runs by default.
# Warm up the filesystem cache for the target dir.,
# both from PowerShell and cmd.exe, to be safe.
gci 'c:\windows\winsxs' -rec >$null; cmd /c dir /s 'c:\windows\winsxs' >$null
Time-Command `
{ @([System.IO.Directory]::EnumerateFiles('c:\windows\winsxs', '*', 'AllDirectories')).Count },
{ (Get-ChildItem -Force -Recurse -File 'c:\windows\winsxs').Count },
{ (cmd /c dir /s /b /a-d 'c:\windows\winsxs').Count },
{ cmd /c 'dir /s /b /a-d c:\windows\winsxs | find /c /v """"' }
On my single-core VMWare Fusion VM with Windows PowerShell v5.1.17134.407 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.523) I get the following timings, from fastest to slowest (scroll to the right to see the Factor
column to show relative performance):
Command Secs (10-run avg.) TimeSpan Factor
------- ------------------ -------- ------
@([System.IO.Directory]::EnumerateFiles('c:\windows\winsxs', '*', 'AllDirectories')).Count 11.016 00:00:11.0158660 1.00
(cmd /c dir /s /b /a-d 'c:\windows\winsxs').Count 15.128 00:00:15.1277635 1.37
cmd /c 'dir /s /b /a-d c:\windows\winsxs | find /c /v """"' 16.334 00:00:16.3343607 1.48
(Get-ChildItem -Force -Recurse -File 'c:\windows\winsxs').Count 24.525 00:00:24.5254979 2.23
Interestingly, both [System.IO.Directory]::EnumerateFiles()
and the Get-ChildItem
solution are significantly faster in PowerShell Core , which runs on top of .NET Core (as of PowerShell Core 6.2.0-preview.4, .NET Core 2.1):
Command Secs (10-run avg.) TimeSpan Factor
------- ------------------ -------- ------
@([System.IO.Directory]::EnumerateFiles('c:\windows\winsxs', '*', 'AllDirectories')).Count 5.094 00:00:05.0940364 1.00
(cmd /c dir /s /b /a-d 'c:\windows\winsxs').Count 12.961 00:00:12.9613440 2.54
cmd /c 'dir /s /b /a-d c:\windows\winsxs | find /c /v """"' 14.999 00:00:14.9992965 2.94
(Get-ChildItem -Force -Recurse -File 'c:\windows\winsxs').Count 16.736 00:00:16.7357536 3.29
[1] [System.IO.Directory]::EnumerateFiles()
is inherently and undoubtedly faster than a Get-ChildItem
solution. In my tests (see section "Performance comparison:" above), [System.IO.Directory]::EnumerateFiles()
beat out cmd /c dir /s
as well, slightly in Windows PowerShell, and clearly so in PowerShell Core, but others report different findings . That said, finding the overall fastest solution is not the only consideration, especially if more than just counting files is needed and if the enumeration needs to be robust . This answer discusses the tradeoffs of the various solutions.
[2] In fact, due to an inefficient implementation as of Windows PowerShell v5.1 / PowerShell Core 6.2.0-preview.4, use of -Path
and -Include
is actually slower than using Get-ChildItem
unfiltered and instead using an additional pipeline segment with ... | Where-Object Name -like *STB*
... | Where-Object Name -like *STB*
, as in the OP - see this GitHub issue .
My guess is this is a lot faster:
$path = 'Fill_in_path_here'
@([System.IO.Directory]::EnumerateFiles($path, '*STB*', 'AllDirectories')).Count
If you do not want to recurse subfolders, change 'AllDirectories'
to 'TopDirectoryOnly'
I would rather do PowerShell as it is a far stronger tool. You might give this .bat file script a try.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET /A "N=0"
FOR /F "delims=" %%f IN ('DIR /S /B /A:-D "C:\path\to\files\*STB*"') DO (SET /A "N=!N!+1")
ECHO There are !N! files.
Summary
P/VM - OS - PS Ver - Files - Winner - Faster By % Seconds - Winner FPS - Loser FPS (Files Per Second)
---- - ----------- - ------ - ------ - ------ - ------------------- - ---------- - ----------------------------
PM - Win 7 - 5.1.1 - 87894 - SysIO - 9% (0.29s) - 27,237 FPS - 24,970 FPS
PM - Win 2012 - 5.1.1 - 114968 - MCND - 8% (0.38s) - 25,142 FPS - 23,226 FPS
VM - Win 2012 - 5.1.1 - 99312 - MCND - 34% (1.57s) - 21,265 FPS - 15,890 FPS
PM - Win 2016 - 5.1.1 - 102812 - SysIO - 2% (0.12s) - 20,142 FPS - 19,658 FPS
VM - Win 2012 R2 - 4.0 - 98396 - MCND - 29-34% (1.56-1.71s) - 19,787 FPS - 14,717 FPS
PM - Win 2008 R2 - 5.0.1 - 46557 - MCND - 13-17% (0.33-0.44s) - 18,926 FPS - 16,088 FPS
VM - Win 2012 R2 - 4.0 - 90906 - MCND - 22% (1.25s) - 16,772 FPS - 13,629 FPS
-- I have explained to MK in the comments that the \\cookies directory and other such directories are intentionally non-traversable so that you od not double-count the files contained within them.
The test MK ran on a VMWare fusion running atop his MAC OS is far from conclusive, and shows execution times are incredibly slow which immediately tipped me off that they were strange results.
In addition, I could not execute the command as written by MK and receive a result of the number of files in the folder, so I have included a snippet in my testing which shows all methods used do give the correct result.
Strangely that one .count method for the MCND command seems to give very biased results on my win7 system, very different from any other system and hugely slower (5x slower) in the initial runs I posted, and varying the most on future runs I tried.
But I think this is due to load, and plan to drop those results if I ever bother to post more, but most of the remaining systems are pretty similar to the results I feel like they could seem redundant if they aren't from very different systems.
$MaxRuns=1000
$Root_Dir="c:\windows\winsxs"
$Results_SysIO=@()
$Results_MCND1=@()
$Results_MCND2=@()
$Results_MCND3=@()
$Results_Meta=@()
FOR ($j=1; $j -le $MaxRuns; $j++) {
Write-Progress -Activity "Testing Mthods for $MaxRuns Runs" -Status "Progress: $($j/$MaxRuns*100)% -- Run $j of $MaxRuns" -PercentComplete ($j/$MaxRuns*100)
# Tests SysIO: @([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count
$Results_SysIO+=Measure-Command { @([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count }
sleep -milliseconds 500
# Tests MCND1 CMD Script: DIR "%~1" /s /a-d ^| FIND /I /V "" | find /c /v ""
$Results_MCND1+=Measure-Command {C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir}
sleep -milliseconds 500
# Tests MCND2 CMD Count: {cmd /c 'dir /s /b /a-d $Root_Dir | find /c /v """"'}
$Results_MCND2+=Measure-Command {cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`"}
sleep -milliseconds 500
# Tests MCND3 PS Count (cmd /c dir /s /b /a-d $Root_Dir).Count
$Results_MCND3+=Measure-Command {(cmd /c dir /s /b /a-d $Root_Dir).Count}
sleep -milliseconds 500
}
$CPU=Get-WmiObject Win32_Processor
""
"CPU: $($($CPU.name).count)x $($CPU.name | select -first 1) - Windows: $($(Get-WmiObject Win32_OperatingSystem).Version) - PS Version: $($PSVersionTable.PSVersion)"
ForEach ($Name in "SysIO","MCND1","MCND2","MCND3") {
$Results_Meta+=[PSCustomObject]@{
Method=$Name
Min=$($($(Get-Variable -Name "Results_$Name" -valueOnly).TotalSeconds|Measure-Object -Minimum).Minimum)
Max=$($($(Get-Variable -Name "Results_$Name" -valueOnly).TotalSeconds|Measure-Object -Maximum).Maximum)
Avg=$($($(Get-Variable -Name "Results_$Name" -valueOnly).TotalSeconds|Measure-Object -Average).Average)
}
}
$Results_Meta | sort Avg | select Method,Min,Max,Avg,@{N="Factor";e={("{0:f2}" -f (([math]::Round($_.Avg / $($Results_Meta | sort Avg | select Avg)[0].avg,2,1))))}}|FT
Time-Command `
{cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`"},
{C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir},
{@([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count},
{(cmd /c dir /s /b /a-d $Root_Dir).Count} $MaxRuns `
""
"Results of Commands - (How many Files were in that Folder?):"
[PSCustomObject]@{
SysIO=$(&{ @([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count })
MCND1=$(&{C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir})
MCND2=$(&{cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`"})
MCND3=$(&{(cmd /c dir /s /b /a-d $Root_Dir).Count})
}
I have Additional Runs I didn't collect yet from additional systems, the Win7 Results are inconsistent though so I'll probably strip them when I have more to add to the list from other systems.
Detailed Findings
Physical Win 7 Laptop - 87894 Files - Loser: MCND is 9% (.29s) Slower - (Winning Method: 27,237 FPS) -- Results are not consistent on re-runs while other systems are.
CPU: 1x Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz - Windows: 6.1.7601 - PS Version: 5.1.14409.1012
CPU: 1x Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz - Windows: 6.1.7601 - PS Version: 5.1.14409.1012
Method Min Max Avg Factor
------ --- --- --- ------
SysIO 3.0190345 6.1287085 3.2174689013 1.00
MCND1 3.3655209 5.9024033 3.5490564665 1.10
MCND3 3.5865989 7.5816207 3.8515160528 1.20
MCND2 3.7542295 7.5619913 3.9471552743 1.23
3.2174689013
0.0000366062
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
@([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count 3.227 00:00:03.2271969 1.00
C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir 3.518 00:00:03.5178810 1.09
cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`" 3.911 00:00:03.9106284 1.21
(cmd /c dir /s /b /a-d $Root_Dir).Count 16.338 00:00:16.3377823 5.06
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
87894 87894 87894 87894
Physical Win 2012 Desktop - 114968 Files - Loser: SysIO is 8% (.38s) Slower - (Winning Method: 25,142 FPS)
CPU: 1x Intel(R) Xeon(R) CPU E5-2407 0 @ 2.20GHz - Windows: 6.3.9600 - PS Version: 5.1.14409.1012
CPU: 1x Intel(R) Xeon(R) CPU E5-2407 0 @ 2.20GHz - Windows: 6.3.9600 - PS Version: 5.1.14409.1012
Method Min Max Avg Factor
------ --- --- --- ------
MCND1 4.4957173 8.6672112 4.5726616326 1.00
MCND3 4.6815509 18.6689706 4.7940769407 1.05
SysIO 4.8789948 5.1625618 4.9476786004 1.08
MCND2 5.0404912 7.2557797 5.0854683543 1.11
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir 4.542 00:00:04.5418653 1.00
(cmd /c dir /s /b /a-d $Root_Dir).Count 4.772 00:00:04.7719769 1.05
@([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count 4.933 00:00:04.9330404 1.09
cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`" 5.086 00:00:05.0855891 1.12
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
114968 114968 114968 114968
VM Win 2012 Server - 99312 Files - Loser: SysIO is 34% (1.57s) Slower - (Winning Method: 21,265 FPS)
CPU: 4x Intel(R) Xeon(R) CPU E7- 2850 @ 2.00GHz - Windows: 6.3.9600 - PS Version: 5.1.14409.1005
CPU: 4x Intel(R) Xeon(R) CPU E7- 2850 @ 2.00GHz - Windows: 6.3.9600 - PS Version: 5.1.14409.1005
Method Min Max Avg Factor
------ --- --- --- ------
MCND1 4.5563908 5.2656374 4.6812307177 1.00
MCND3 4.6696518 5.3846231 4.9064852835 1.05
MCND2 5.0559205 5.5583717 5.15425442679999 1.10
SysIO 6.036294 6.7952711 6.254027334 1.34
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir 4.669 00:00:04.6689048 1.00
(cmd /c dir /s /b /a-d $Root_Dir).Count 4.934 00:00:04.9336925 1.06
cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`" 5.153 00:00:05.1532386 1.10
@([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count 6.239 00:00:06.2389727 1.34
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
99312 99312 99312 99312
Physical Win 2016 Server - 102812 Files - Loser: MCND is 2% (0.12s) Slower - (Winning Method: 20,142 FPS)
CPU: 2x Intel(R) Xeon(R) CPU E5-2667 v4 @ 3.20GHz - Windows: 10.0.14393 - PS Version: 5.1.14393.2608
CPU: 2x Intel(R) Xeon(R) CPU E5-2667 v4 @ 3.20GHz - Windows: 10.0.14393 - PS Version: 5.1.14393.2608
Method Min Max Avg Factor
------ --- --- --- ------
SysIO 5.0414178 5.5279055 5.1043614001 1.00
MCND3 5.0468476 5.4673033 5.23160342460001 1.02
MCND1 5.1649438 5.6745749 5.26664923669999 1.03
MCND2 5.3280266 5.7989287 5.3747728434 1.05
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
@([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count 5.156 00:00:05.1559628 1.00
(cmd /c dir /s /b /a-d $Root_Dir).Count 5.256 00:00:05.2556244 1.02
C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir 5.272 00:00:05.2722298 1.02
cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`" 5.375 00:00:05.3747287 1.04
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
102812 102812 102812 102812
VM Win 2012 R2 Server - 98396 Files - Loser: SysIO 29-34% (1.56-1.71s) Slower - (Winning Method: 19,787 FPS)
CPU: 2x Intel(R) Xeon(R) CPU E7- 2850 @ 2.00GHz - Windows: 6.3.9600 - PS Version: 4.0
CPU: 2x Intel(R) Xeon(R) CPU E7- 2850 @ 2.00GHz - Windows: 6.3.9600 - PS Version: 4.0
Method Min Max Avg Factor
------ --- --- --- ------
MCND1 4.7007419 5.9567352 4.97285509330001 1.00
MCND2 5.2086999 6.7678172 5.4849721167 1.10
MCND3 5.0116501 8.7416729 5.71391797679999 1.15
SysIO 6.2400687 7.414201 6.6862204345 1.34
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
C:\Admin\TestMCNDFindFiles1.cmd $Root... 5.359 00:00:05.3592304 1.00
cmd /c `"dir /s /b /a-d $Root_Dir `| ... 5.711 00:00:05.7107644 1.07
(cmd /c dir /s /b /a-d $Root_Dir).Count 6.173 00:00:06.1728413 1.15
@([System.IO.Directory]::EnumerateFil... 6.921 00:00:06.9213833 1.29
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
98396 98396 98396 98396
Physical Win 2008 R2 Server - 46557 Files - Loser: SysIO 13-17% (0.33-0.44s) Slower - (Winning Method: 18,926 FPS)
CPU: 2x Intel(R) Xeon(R) CPU 5160 @ 3.00GHz - Windows: 6.1.7601 - PS Version: 5.0.10586.117
CPU: 2x Intel(R) Xeon(R) CPU 5160 @ 3.00GHz - Windows: 6.1.7601 - PS Version: 5.0.10586.117
Method Min Max Avg Factor
------ --- --- --- ------
MCND3 2.2370018 2.8176253 2.4653543378 1.00
MCND1 2.4063578 2.8108379 2.5373719772 1.03
MCND2 2.5953631 2.9085969 2.7312907064 1.11
SysIO 2.7207865 30.335369 2.8940406601 1.17
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
(cmd /c dir /s /b /a-d $Root_Dir).Count 2.500 00:00:02.5001477 1.00
C:\Admin\TestMCNDFindFiles1.cmd $Root_Dir 2.528 00:00:02.5275259 1.01
cmd /c `"dir /s /b /a-d $Root_Dir `| find /c /v `"`"`"`"`" 2.726 00:00:02.7259539 1.09
@([System.IO.Directory]::EnumerateFiles($Root_Dir, '*', 'AllDirectories')).Count 2.826 00:00:02.8259697 1.13
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
46557 46557 46557 46557
VMWare Win 2012 R2 Server - 90906 Files - Loser: SysIO 23% (1.25s) Slower - (Winning Method: 15,722 FPS)
CPU: 4x Intel(R) Xeon(R) CPU E7- 2850 @ 2.00GHz - Windows: 6.3.9600 - PS Version: 4.0
CPU: 4x Intel(R) Xeon(R) CPU E7- 2850 @ 2.00GHz - Windows: 6.3.9600 - PS Version: 4.0
Method Min Max Avg Factor
------ --- --- --- ------
MCND1 5.0516057 6.4537866 5.423386317 1.00
MCND3 5.3297157 7.1722929 5.9030135773 1.09
MCND2 5.5460548 7.0356455 5.931334868 1.09
SysIO 6.2059999 19.5145373 6.6747122712 1.23
Command Secs (1000-run avg.) TimeSpan Factor
------- -------------------- -------- ------
C:\Admin\TestMCNDFindFiles1.cmd $Root... 5.409 00:00:05.4092046 1.00
(cmd /c dir /s /b /a-d $Root_Dir).Count 5.936 00:00:05.9358832 1.10
cmd /c `"dir /s /b /a-d $Root_Dir `| ... 6.069 00:00:06.0689899 1.12
@([System.IO.Directory]::EnumerateFil... 6.557 00:00:06.5571859 1.21
Results of Commands - (How many Files were in that Folder?):
SysIO MCND1 MCND2 MCND3
----- ----- ----- -----
90906 90906 90906 90906
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.