您当前的位置: 首页 > 

Linux小百科

暂无认证

  • 0浏览

    0关注

    1185博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

Linux小百科 发布时间:2021-05-13 09:36:50 ,浏览量:0

这篇文章主要介绍了Powershell 之批量获取文件大小的实现代码

效果图:

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

核心代码:

$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 确认即可。

开启:

set-executionpolicy remotesigned

关闭:

Set-ExecutionPolicy Restricted
关注
打赏
1665632672
查看更多评论
立即登录/注册

微信扫码登录

0.0396s