本帖最后由 went 于 2021-10-24 22:29 编辑
回复 9# asy666 - #&@cls&cd /d "%~dp0" & powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause&exit
- #图片格式
- $pic_ext = 'jpg png'
- #视频格式
- $video_ext = 'mp4 mkv flv'
- #输出文件
- $file_info = 'info.txt'
- #函数 格式化显示数据
- function Fmt-Data($name,$pic,$video,$size){
- $unit = @('Byte','KB','MB','GB','TB')
- $index = 0
- $num = $size
- while($size -ge 1024){
- ++$index
- $size /= 1024
- $num = $size % 1024
- }
- $str_size = '' + [Math]::Round($num,[MidpointRounding]::AwayFromZero) + $unit[$index]
- if($video -gt 0){
- $str_video = '_' + $video + 'v'
- } else {
- $str_video = ''
- }
- return '{0} [{1}p{2}-{3}]' -f $name,$pic,$str_video,$str_size
- }
- #遍历
- $pic_pattern = '^\.(' + $pic_ext + ')$' -replace '\s+','|'
- $video_pattern = '^\.(' + $video_ext + ')$' -replace '\s+','|'
- $total_size = $total_pic = $total_video = 0
- Get-ChildItem | Where-Object { [System.IO.Directory]::Exists($_.FullName) } | foreach {
- $size = $pic = $video = 0
- Get-ChildItem -Recurse -LiteralPath $_ | foreach {
- $size += $_.Length
- if($_.Extension -match $pic_pattern){
- ++$pic
- } elseif($_.Extension -match $video_pattern){
- ++$video
- }
- }
- $total_size += $size
- $total_pic += $pic
- $total_video += $video
- $new_name = Fmt-Data -name $_.Name -pic $pic -video $video -size $size
- $new_name
- Invoke-Expression ('cmd /c rename "{0}" "{1}"' -f $_.FullName,$new_name)
- '--------------'
- }
- "`r`n--------------"
- $str = Fmt-Data -name (Get-Item .).Name -pic $total_pic -video $total_video -size $total_size
- $str
- $str | Out-File $file_info
- "--------------"
复制代码
|