适用于数量不是太多,以免影响速度。若10万以上可以不用。须换NET版才能提速。
POWERSHELL 运行。- $Lists = New-Object System.Text.StringBuilder;
- $files = ls 'D:\1\' -r | ?{$_.Directory};
- $m = $files.Count.tostring().Length;
- Foreach ( $i in $files )
- {
- $index++;
- $ref = $i.Length;
- switch ( $ref.tostring().length )
- {
- {$_ -le 3} { $length = "{0:0.000} Byte" -f ($ref);break}
- {$_ -le 6} { $length = "{0:0.000} KB" -f ($ref/1KB);break}
- {$_ -le 9} { $length = "{0:0.000} MB" -f ($ref/1MB);break}
- $_ { $length = "{0:0.000} GB" -f ($ref/1GB)}
- }
- $n = '[' + $index.tostring().padleft($m,' ') + ']';
- [void]$Lists.AppendLine($n+' '+$i.name);
- [void]$Lists.AppendLine(' '*($m+3)+$length);
- [void]$Lists.AppendLine(' '*($m+3)+$i.LastWriteTime);
- [void]$Lists.AppendLine(' '*($m+3)+$i.FullName);
- [void]$Lists.AppendLine('');
- }
- [IO.File]::WriteAllLines("$pwd\输出.log",$Lists,[text.encoding]::Default);
复制代码
|