gpt4 book ai didi

powershell - Powershell 中的 Expand-Archive 无法提取嵌套文件夹和文件

转载 作者:行者123 更新时间:2023-12-04 21:04:29 26 4
gpt4 key购买 nike

我有以下简单的 powershell 将 zip 文件夹(包含其他文件夹和仅日志文件)提取到目标

$FolderPath = "C:\Temp\Whatever"

Expand-Archive -Path "$FolderPath\logs.zip" -DestinationPath "$FolderPath\logs"

不幸的是,这会返回一大堆错误,如下所示....
Remove-Item : Cannot find path 'C:\Temp\Whatever\logs\1_Selenium SEPA-Test\Attempt1\1_Start VM's\Release\1_Initialize Agent.log' because it does not exist.
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:410 char:46
+ ... $expandedItems | % { Remove-Item $_ -Force -Recurse }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Temp\Whateve...alize Agent.log:String) [Remove-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand

Remove-Item : Cannot find path 'C:\Temp\Whatever\logs\1_Selenium SEPA-Test\Attempt1\1_Start VM's\Release\1_Initialize Job.log' because it does not exist.
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:410 char:46
+ ... $expandedItems | % { Remove-Item $_ -Force -Recurse }
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Temp\Whateve...tialize Job.log:String) [Remove-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand

以及大量其他类似的错误

我可以确认第一个错误中引用的文件 C:\Temp\Whatever\logs\1_Selenium SEPA-Test\Attempt1\1_Start VM's\Release\1_Initialize Agent.log确实存在于等效位置的 zip 文件夹中...

enter image description here

脚本结束后,我会在指定的目录中看到一个不完整的文件夹。

enter image description here

这里发生了什么?

谢谢,

最佳答案

我在过去和一位同事遇到过这个模块的问题,我拼凑了以下内容

# This script was created to extract the contents of multiple ZIP files located in a directory
# structure. Each ZIP files is extracted within the folder it resides.

# File path
$filepath = Get-ChildItem -Path 'C:\Users\Luke\Desktop\ArchivedScripts\' -Filter *.zip -Recurse

# convert filepath to NameSpace object
$shell = new-object -com shell.application

# ForEach Loop processes each ZIP file located within the $filepath variable
foreach($file in $filepath)
{
$zip = $shell.NameSpace($file.FullName)
foreach($item in $zip.items())
{
$shell.Namespace($file.DirectoryName).copyhere($item)
}
Remove-Item $file.FullName
}

也许这有点用?

关于powershell - Powershell 中的 Expand-Archive 无法提取嵌套文件夹和文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50106917/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com