test.ps1- function formatSize($n){
- if($n -ge 1gb){
- $s = ($n/1gb).ToString('0.0') + 'GB'
- }elseif($n -ge 1mb){
- $s = ($n/1mb).ToString('0.0') + 'MB'
- }elseif($n -ge 1kb){
- $s = ($n/1kb).ToString('0.0') + 'KB'
- }else {$s = '' + $n + 'B'}
- return '共计' + $s
- }
- $arr = dir 'D:\Test\*' -Recurse -Force | ?{ $_ -is [IO.FileInfo] }
- $arr | group Extension | %{'' + $_.Count + '个' + $(if($_.Name){$_.Name -replace '\.'}else{'无扩展名'})} > D:\结果.Log
- formatSize(($arr | measure Length -Sum).Sum) >> D:\结果.Log
复制代码
|