Dan*_*ano -2 powershell powerpoint
我有一堆PowerPoint演示文稿,我需要提取其中每一个的图像。我注意到(通过使用WinRar打开PPT文件)它包含一个“媒体”文件夹,所有图像都位于该文件夹中。是否有任何形式可将每个文件的“媒体”文件夹提取到每个文件的单独文件夹中?
我写这真快,所以如果有一个更好的办法,或者至少,一个更清洁的方式来完成你以后我不会感到惊讶。它被编写为可以在有和没有嵌入式媒体文件夹的情况下使用。
为了进行测试,我在桌面上有一个名为pptx的文件夹,其中有四个* .pptx文件。快速脚本完成后,它已在同一文件夹中为每个PowerPoint文件创建了一个文件夹。在这些文件夹中的每个文件夹中都是带有您要查找的文件的媒体文件夹,或者是指示找不到媒体文件夹的文本文件。再说一次,也许有一种更清洁的方法,但是在那之前,这应该可行。
$Path = 'C:\users\tommymaynard\Desktop\pptx'
$Files = Get-ChildItem -Path $Path
Foreach ($File in $Files) {
New-Item -Path $File.DirectoryName -ItemType Directory -Name $File.BaseName | Out-Null
If (Get-Command -Name Expand-Archive) {
Expand-Archive -Path $File.FullName -OutputPath $File.FullName.Split('.')[0]
} Else {
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($File.FullName,$File.FullName.Split('.')[0])
} # End If-Else.
If (Test-Path -Path "$($File.FullName.Split('.')[0])\ppt\media") {
Move-Item -Path "$($File.FullName.Split('.')[0])\ppt\media" -Destination $File.FullName.Split('.')[0]
Get-ChildItem -Path $File.FullName.Split('.')[0] | Where-Object {$_.Name -ne 'media'} | Remove-Item -Recurse
} Else {
Get-ChildItem -Path $File.FullName.Split('.')[0] | Remove-Item -Recurse
New-Item -Path $File.FullName.Split('.')[0] -ItemType File -Name 'No media folder.txt' | Out-Null
} # End If-Else.
} # End Foreach.
Run Code Online (Sandbox Code Playgroud)
编辑:使用.NET是这样不是扩大-归档快得多!如果您追求的是速度,并且正在运行包含Expand-Archive的PowerShell版本,则将Get-Command -Name Expand-Archive更改为$ true -eq $ false强制使用.NET。或者,或者只是转储第一个If-Else并提取该.NET代码...让我们知道您是否需要进一步的帮助。
Edit2:我在自己的博客上撰写了有关此帖子的文章:http : //tommymaynard.com/extract-media-folder-from-powerpoint-files-2017/。它具有我代码的更新版本。
| 归档时间: |
|
| 查看次数: |
229 次 |
| 最近记录: |