标题: [文件操作] [分享]BAT+VBS+PowerShell获取PPT文件页数和大小并重命名文件 [打印本页]
作者: Batcher 时间: 2023-11-13 17:09 标题: [分享]BAT+VBS+PowerShell获取PPT文件页数和大小并重命名文件
使用下面的脚本可以获取PPT文件的路径和页数。
怎样增加获取一个属性:文件大小。
最后把页数和文件大小添加到原始PPT文件名的后面。
例如,原始文件:
中国风PPT模板A.pptx
中国风PPT模板B.pptx
执行代码后得到:
中国风PPT模板A-16-4484791.pptx
中国风PPT模板B-19-2039435.pptx
count_all.bat- @echo off
- set "FileOut=results.txt"
- type nul > "%FileOut%"
- for /r %%f in (*.pptx) do (
- echo Trying to open: %%f
- cscript //nologo count_slides.vbs "%%f" >> "%FileOut%"
- )
复制代码
count_slides.vbs- On Error Resume Next
- If WScript.Arguments.Count < 1 Then
- WScript.Echo "Usage: cscript count_slides.vbs <ppt_path>"
- WScript.Quit 1
- End If
- pptPath = WScript.Arguments(0)
- Set objPPT = CreateObject("PowerPoint.Application")
- Set objPresentation = objPPT.Presentations.Open(pptPath)
- If Err Then
- WScript.Echo "Couldn't open file: " & pptPath
- WScript.Quit 1
- End If
- WScript.Echo pptPath & ":" & objPresentation.Slides.Count
- objPresentation.Close
- objPPT.Quit
复制代码
作者: Batcher 时间: 2023-11-13 17:10
【方案1】
把 count_all.bat 修改如下:- @echo off
- set "FileOut=results.txt"
- type nul > "%FileOut%"
- for /r %%f in (*.pptx) do (
- echo Trying to open: %%f
- cscript //nologo count_slides.vbs "%%f" >> "%FileOut%"
- )
- for /f "tokens=2* delims=:" %%a in ('type ""%FileOut%""') do (
- for %%i in ("%%~dpnxa") do (
- ren "%%~dpnxa" "%%~na-%%b-%%~zi%%~xa"
- )
- )
复制代码
作者: Batcher 时间: 2023-11-13 17:15
【方案2】
不使用原来的bat和vbs,直接使用新的 2.bat 脚本:- <# :
- @echo off
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0' |Out-String|Invoke-Expression"
- #>
- $Shell = New-Object -ComObject Shell.Application;
- Get-ChildItem *.pptx | ForEach-Object {
- $Folder = $Shell.Namespace($_.DirectoryName);
- $File = $Folder.ParseName($_.Name);
- $n=$Folder.GetDetailsOf($File, 158);
- $size=$Folder.GetDetailsOf($File, 1);
- ($_.fullname+":"+[string]$n+":"+$size)>>results.txt;
- ren $_.fullname ("{0}-{1}-{2}.pptx" -f $_.basename,$n,$size)
- }
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |