【发布时间】:2014-01-23 22:33:44
【问题描述】:
全部,
我正在使用 PSv1 的 Power Shell 社区扩展,并且正在正确创建 ZIP 文件。但是,我只想要 ZIP 文件中的图像,我想从 ZIP 文件中删除该文件夹。
我有一个名为 newpictures 的文件夹,它被压缩了。然后我使用 Power Shell Community Extensions 中的 -flattenpaths 选项将所有图像放在基本路径中,但文件夹仍然存在。
我一直在网上寻找解决方案。我不确定我是否有这个权利,所以有人可以在我继续之前查看这段代码并让我知道这是否正确吗?
if (test-path $PSCXInstallDir) {
write-zip -path "Microsoft.PowerShell.Core\FileSystem::$TestSite" -outputpath "Microsoft.PowerShell.Core\FileSystem::$ZipFileCreationDir\$ZipFileName" -noclobber -quiet -flattenpaths -level 9
start-sleep -seconds 30
if (test-path $ZipFileCreationDir\$ZipFileName) {
$ShellApp = new-object -com shell.application
$TheZipFile = $ShellApp.namespace("$ZipFileCreationDir\$ZipFileName")
$TheZipFile.items() | where-object {$_.name -eq $FolderToCompress} | remove-item $FolderToCompress
}
}
变量是:
$PSCXInstallDir = "C:\Program Files\PowerShell Community Extensions"
$TestSite = "\\10.0.100.3\www2.varietydistributors.com\catalog\newpictures"
$ZipFileCreationDir = "\\10.0.100.3\www2.varietydistributors.com\catalog"
$ZipFileName = "vdi-test.zip"
$FolderToCompress = "newpictures"
提前感谢您的任何反馈。简而言之,我只想删除 ZIP 文件中的单个文件夹。
【问题讨论】:
标签: powershell