[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
test.bat
ANSI编码
  1. #&@cls&cd /d "%~dp0" & powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause&exit
  2. #图片格式
  3. $pic_ext = 'jpg png'
  4. #视频格式
  5. $video_ext = 'mp4 mkv flv'
  6. #遍历
  7. $pic_pattern = '^\.(' + $pic_ext + ')$' -replace '\s+','|'
  8. $video_pattern = '^\.(' + $video_ext + ')$' -replace '\s+','|'
  9. Get-ChildItem | Where-Object { [System.IO.Directory]::Exists($_.FullName) } | foreach {
  10.     $size = $pic = $video = 0
  11.     Get-ChildItem -Recurse $_ | foreach {
  12.         $size += $_.Length
  13.         if($_.Extension -match $pic_pattern){
  14.             ++$pic
  15.         } elseif($_.Extension -match $video_pattern){
  16.             ++$video
  17.         }
  18.     }
  19.     if($size -lt 1024){
  20.         $size_str = '' + [int]$size + 'Byte'
  21.     } elseif($size -lt 1024 * 1024){
  22.         $size_str = '' + [int]($size / 1024) + 'KB'
  23.     } elseif($size -lt 1024 * 1024 * 1024){
  24.         $size_str = '' + [int]($size / 1024 / 1024) + 'MB'
  25.     } else {
  26.         $size_str = '' + [int]($size / 1024 / 1024 / 1024) + 'GB'
  27.     }
  28.     if($video -gt 0){ $str = ('_' + $video + 'v') } else { $str = '' }
  29.     $new_name = '{0} [{1}p{2}-{3}]' -f $_.Name,$pic,$str,$size_str
  30.     $new_name
  31. Invoke-Expression ('cmd /c rename "{0}" "{1}"' -f $_.FullName,$new_name)
  32.     '--------------'
  33. }
复制代码

TOP

回复 3# asy666
  1. #&@cls&cd /d "%~dp0" & powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause&exit
  2. #图片格式
  3. $pic_ext = 'jpg png'
  4. #视频格式
  5. $video_ext = 'mp4 mkv flv'
  6. #输出文件
  7. $file_info = 'info.txt'
  8. #遍历
  9. $pic_pattern = '^\.(' + $pic_ext + ')$' -replace '\s+','|'
  10. $video_pattern = '^\.(' + $video_ext + ')$' -replace '\s+','|'
  11. &{
  12. Get-ChildItem | Where-Object { [System.IO.Directory]::Exists($_.FullName) } | foreach {
  13. $size = $pic = $video = 0
  14. Get-ChildItem -Recurse -LiteralPath $_ | foreach {
  15. $size += $_.Length
  16. if($_.Extension -match $pic_pattern){
  17. ++$pic
  18. } elseif($_.Extension -match $video_pattern){
  19. ++$video
  20. }
  21. }
  22. if($size -lt 1024){
  23. $size_str = '' + [int]$size + 'Byte'
  24. } elseif($size -lt 1024 * 1024){
  25. $size_str = '' + [int]($size / 1024) + 'KB'
  26. } elseif($size -lt 1024 * 1024 * 1024){
  27. $size_str = '' + [int]($size / 1024 / 1024) + 'MB'
  28. } else {
  29. $size_str = '' + [int]($size / 1024 / 1024 / 1024) + 'GB'
  30. }
  31. if($video -gt 0){ $str = ('_' + $video + 'v') } else { $str = '' }
  32. $new_name = '{0} [{1}p{2}-{3}]' -f $_.Name,$pic,$str,$size_str
  33. $new_name
  34. Write-Host $new_name
  35. Invoke-Expression ('cmd /c rename "{0}" "{1}"' -f $_.FullName,$new_name)
  36. Write-Host '--------------'
  37. }
  38. } | Out-File $file_info
复制代码

TOP

本帖最后由 went 于 2021-10-24 22:29 编辑

回复 9# asy666
  1. #&@cls&cd /d "%~dp0" & powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause&exit
  2. #图片格式
  3. $pic_ext = 'jpg png'
  4. #视频格式
  5. $video_ext = 'mp4 mkv flv'
  6. #输出文件
  7. $file_info = 'info.txt'
  8. #函数 格式化显示数据
  9. function Fmt-Data($name,$pic,$video,$size){
  10. $unit = @('Byte','KB','MB','GB','TB')
  11. $index = 0
  12. $num = $size
  13. while($size -ge 1024){
  14. ++$index
  15. $size /= 1024
  16. $num = $size % 1024
  17. }
  18. $str_size = '' + [Math]::Round($num,[MidpointRounding]::AwayFromZero) + $unit[$index]
  19. if($video -gt 0){
  20. $str_video = '_' + $video + 'v'
  21. } else {
  22. $str_video = ''
  23. }
  24. return '{0} [{1}p{2}-{3}]' -f $name,$pic,$str_video,$str_size
  25. }
  26. #遍历
  27. $pic_pattern = '^\.(' + $pic_ext + ')$' -replace '\s+','|'
  28. $video_pattern = '^\.(' + $video_ext + ')$' -replace '\s+','|'
  29. $total_size = $total_pic = $total_video = 0
  30. Get-ChildItem | Where-Object { [System.IO.Directory]::Exists($_.FullName) } | foreach {
  31. $size = $pic = $video = 0
  32. Get-ChildItem -Recurse -LiteralPath $_ | foreach {
  33. $size += $_.Length
  34. if($_.Extension -match $pic_pattern){
  35. ++$pic
  36. } elseif($_.Extension -match $video_pattern){
  37. ++$video
  38. }
  39. }
  40. $total_size += $size
  41. $total_pic += $pic
  42. $total_video += $video
  43. $new_name = Fmt-Data -name $_.Name -pic $pic -video $video -size $size
  44. $new_name
  45. Invoke-Expression ('cmd /c rename "{0}" "{1}"' -f $_.FullName,$new_name)
  46. '--------------'
  47. }
  48. "`r`n--------------"
  49. $str = Fmt-Data -name (Get-Item .).Name -pic $total_pic -video $total_video -size $total_size
  50. $str
  51. $str | Out-File $file_info
  52. "--------------"
复制代码

TOP

返回列表