[英]Process directory statistics recursively using Powershell
I am currently using a script I wrote to use a Logparser query against a directory recursively to produce the following output: 我当前正在使用编写的脚本来递归地对目录使用Logparser查询,以产生以下输出:
QTY TOT KB AVRG KB MAXM KB MINM KB
------- --------- ------- ------- -------
3173881 175101609 55 85373 0
I would like to reproduce this using powershell in an attempt to make collecting this information more portable. 我想使用powershell来重现此信息,以使收集此信息的操作更加方便。 (Not needing to install / copy logparser)
(不需要安装/复制logparser)
I searched and attempted to manipulate what examples I have found but can't quite get the structure down. 我搜索并尝试操纵发现的示例,但无法完全理解该示例。
Here is the closest I have gotten: 这是我最近得到的:
Get-ChildItem -Recurse | Measure-Object -sum Length | Select-Object Count,Average,Sum
This returns: 返回:
Count Average Sum
----- ------- ---
44663 40861708776
Any suggestions? 有什么建议么? I would prefer to stick to a "one line" command if possible.
如果可能,我希望坚持使用“一行”命令。
Measure-Object
仅执行其所要执行的操作,因此,如果仅使用-Sum
,则只会得到Sum。
Get-ChildItem -Recurse -File | Measure-Object -Sum -Average -Maximum -Minimum -Property Length | Select Count, Average, Sum, Maximum, Minimum
Get-ChildItem is pretty slow; Get-ChildItem相当慢; what about using RoboCopy to list the folder contents?
使用RoboCopy列出文件夹内容怎么办?
$Folder = "D:\Downloads"
robocopy $Folder $Folder /S /L /BYTES /NJH /NJS /NDL /V |
ForEach-Object { (-split $_)[1] } |
Measure-Object -Maximum -Minimum -Sum -Average |
Format-Table
Which goes to a one-liner: 这是单线的:
robocopy $Folder $Folder /S /L /BYTES /NJH /NJS /NDL /V |%{(-split $_)[1]}|measure -a -s -ma -mi | ft
Robocopy options are: Robocopy选项包括:
/S - subdirectories (excluding empty ones)
/L - list files, don't do any copying or moving
/BYTES - show sizes in bytes, with no commas or anything
/NJH and /NJS - no header and summary lines in the output
/NDL - don't list directories
/V - verbose (do list individual files and their sizes)
Then the ForEach splits the output to drop the filename and robocopy status and just keep the size, and measure-object calculates the results, and format-table turns it into a nicer looking table output. 然后,ForEach将输出拆分以删除文件名和robocopy状态并仅保留大小,然后measure-object计算结果,而format-table将其转换为外观更好的表输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.