找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 19851|回复: 2

[文件操作] [分享]BAT+VBS+PowerShell获取PPT文件页数和大小并重命名文件

[复制链接]
发表于 2023-11-13 17:09:44 | 显示全部楼层 |阅读模式
使用下面的脚本可以获取PPT文件的路径和页数。
怎样增加获取一个属性:文件大小。
最后把页数和文件大小添加到原始PPT文件名的后面。

例如,原始文件:
中国风PPT模板A.pptx
中国风PPT模板B.pptx

执行代码后得到:
中国风PPT模板A-16-4484791.pptx
中国风PPT模板B-19-2039435.pptx

count_all.bat
  1. @echo off
  2. set "FileOut=results.txt"
  3. type nul > "%FileOut%"
  4. for /r %%f in (*.pptx) do (
  5.     echo Trying to open: %%f
  6.     cscript //nologo count_slides.vbs "%%f" >> "%FileOut%"
  7. )
复制代码
count_slides.vbs
  1. On Error Resume Next
  2. If WScript.Arguments.Count < 1 Then
  3.     WScript.Echo "Usage: cscript count_slides.vbs <ppt_path>"
  4.     WScript.Quit 1
  5. End If
  6. pptPath = WScript.Arguments(0)
  7. Set objPPT = CreateObject("PowerPoint.Application")
  8. Set objPresentation = objPPT.Presentations.Open(pptPath)
  9. If Err Then
  10.     WScript.Echo "Couldn't open file: " & pptPath
  11.     WScript.Quit 1
  12. End If
  13. WScript.Echo pptPath & ":" & objPresentation.Slides.Count
  14. objPresentation.Close
  15. objPPT.Quit
复制代码
 楼主| 发表于 2023-11-13 17:10:42 | 显示全部楼层
【方案1】

把 count_all.bat 修改如下:
  1. @echo off
  2. set "FileOut=results.txt"
  3. type nul > "%FileOut%"
  4. for /r %%f in (*.pptx) do (
  5.     echo Trying to open: %%f
  6.     cscript //nologo count_slides.vbs "%%f" >> "%FileOut%"
  7. )
  8. for /f "tokens=2* delims=:" %%a in ('type ""%FileOut%""') do (
  9.     for %%i in ("%%~dpnxa") do (
  10.         ren "%%~dpnxa" "%%~na-%%b-%%~zi%%~xa"
  11.     )
  12. )
复制代码
 楼主| 发表于 2023-11-13 17:15:08 | 显示全部楼层
【方案2】

不使用原来的bat和vbs,直接使用新的 2.bat 脚本:
  1. <# :
  2. @echo off
  3. powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0' |Out-String|Invoke-Expression"
  4. #>
  5. $Shell = New-Object -ComObject Shell.Application;
  6. Get-ChildItem *.pptx | ForEach-Object {
  7.         $Folder = $Shell.Namespace($_.DirectoryName);
  8.         $File = $Folder.ParseName($_.Name);
  9.         $n=$Folder.GetDetailsOf($File, 158);
  10.         $size=$Folder.GetDetailsOf($File, 1);
  11.         ($_.fullname+":"+[string]$n+":"+$size)>>results.txt;
  12.         ren $_.fullname ("{0}-{1}-{2}.pptx" -f $_.basename,$n,$size)
  13. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-18 10:25 , Processed in 0.016966 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表