首页 > 解决方案 > Powershell 解压缩扩展名为 .zip 的文件并将其移动到另一个文件夹

问题描述

我希望你们中的一些人可以帮助我。我在修改 powershell 脚本时遇到了困难。

该脚本检查特定文件夹(源)中的 zip 文件(文件名是固定值)并将其移动到另一个文件夹(目标),但是我需要一个脚本来检查 .zip 扩展名,而不是固定值和也将其移动到另一个文件夹。我现在正在使用这个脚本:

powershell.exe -nologo -noprofile -command "& { $shell = New-Object -COM Shell.Application; $target = $shell.NameSpace('D:\Anlagen'); $zip = $shell.NameSpace('C:\Temp\Rechnungen\Outlook'); $target.CopyHere($zip.Items(), 16); }"

如您所见,我需要将此脚本作为批处理文件。

标签: powershellbatch-fileunzip

解决方案


用于Expand-Archive将文件解压缩到一个目录,然后从您的批处理脚本中,将文件复制到其他地方。如果您需要从批处理脚本执行此操作:

powershell.exe -c "Expand-Archive -Path 'C:\path\to\archive.zip' -DestinationPath 'C:\unzip\directory'"
xcopy /s /e /t "C:\unzip\directory" "C:\final\destination\directory"

请注意,UNC 路径也应与任一命令一起使用,而不仅仅是本地路径。


推荐阅读