源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Powershell 之批量获取文件大小的实现代码

  • 时间:2022-05-29 13:37 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Powershell 之批量获取文件大小的实现代码
效果图: [img]http://files.jb51.net/file_images/article/201611/20161127205513.png[/img] 核心代码
$startFolder = "D:\"
$colItems = (Get-ChildItem $startFolder | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)
foreach ($i in $colItems)
{
 $subFolderItems = (Get-ChildItem $i.FullName -recurse | Measure-Object -property length -sum)
 $FileSize="{0:N2}" -f ($subFolderItems.sum / 1GB)
 $Unit='GB'
 if($FileSize -lt 1)
 {
  $FileSize="{0:N2}" -f ($subFolderItems.sum / 1MB)
  $Unit='MB'
 }
 write-host $i.FullName ' -- ' $FileSize $Unit -fore green
}
注意:如果是第一次运行需要开启执行脚本权限。 在powershell中运行如下命令,然后 Y 确认即可。 开启:[code]set-executionpolicy remotesigned[/code] 关闭:[code]Set-ExecutionPolicy Restricted[/code]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部