标题: [文件操作] 批处理怎样批量删除word文档的页脚? [打印本页]
作者: karmane 时间: 2022-9-19 21:12 标题: 批处理怎样批量删除word文档的页脚?
求一个批处理,可删除当前目录,以及子目录下所有*.doc 或 *.docx 文档的页脚,急。。。。。感谢!
作者: flashercs 时间: 2022-9-19 22:11
本帖最后由 flashercs 于 2022-9-19 23:47 编辑
- <#*,:&cls
- @echo off
- cd /d "%~dp0"
- powershell -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~f0\" -ReadCount 0 | Out-String)))"
- pause
- exit /b
- #>
- $wordApp = New-Object -ComObject Word.Application -ErrorAction Stop
- Get-ChildItem -Path .\*.doc, .\*.docx -Recurse | Where-Object { -not $_.PSIsContainer } | ForEach-Object {
- $_ | Resolve-Path -Relative
- try {
- $doc = $wordApp.Documents.Open($_.FullName)
- foreach ($section in $doc.Sections) {
- foreach ($footer in $section.Footers) {
- $null = $footer.Range.Delete()
- }
- }
- } finally {
- if ($doc) {
- $doc.Close([ref]$true)
- $doc = $null
- }
- }
- trap {}
- }
- $wordApp.Quit()
复制代码
作者: karmane 时间: 2022-9-19 22:27
回复 2# flashercs
运行窗口报了异常,子目录文档的页脚还在呢。。。
[img][/img]
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |