简体   繁体   English

Powershell zip/move 的问题

[英]Issues with Powershell zip/move

I am creating a powershell script that is working for the most part;我正在创建一个大部分工作的 powershell 脚本; however, the zip folder I am creating cannot be opened and is appearing as a 'file' instead of a 'compressed'...但是,我正在创建的 zip 文件夹无法打开,并且显示为“文件”而不是“压缩”...

Any idea what I am doing wrong?知道我做错了什么吗? I am not geting any errors and the file is moving, renaming, copying etc. correctly.我没有收到任何错误,文件正在正确移动、重命名、复制等。

script to compress folder and move压缩文件夹并移动的脚本

Compress-Archive -Path C:\test\import -DestinationPath C:\test\archive
$filenameFormat = "archive.zip" + " " + (Get-Date -Format "yyyyMMdd-HHmmss")
Start-Sleep -Seconds 3
Rename-Item -Path "C:\test\archive.zip" -NewName $filenameFormat
Copy-Item -Path C:\test\$filenameFormat -Destination C:\test\allarchivefiles
Start-Sleep -Seconds 3
Move-Item -Path C:\test\$filenameFormat -Destination C:\test2
Remove-Item -Path c:\test\import\* -include *.csv

Your issue is that you're choosing a filename where.zip is just in the middle and not at the end.您的问题是您选择了一个文件名,其中 .zip 位于中间而不是末尾。 Changing $filenameFormat to this fixes it:将 $filenameFormat 更改为此修复它:

$filenameFormat = "archive" + " " + (Get-Date -Format "yyyyMMdd-HHmmss") + '.zip'

Although I'd probably do it more compactly by setting the filename directly in a variable then using that, like this:虽然我可能会通过直接在变量中设置文件名然后使用它来更紧凑地完成它,如下所示:

$Archive = "C:\test\archive $(Get-Date -Format 'yyyyMMdd-HHmmss').zip"
Compress-Archive -Path C:\test\import -DestinationPath $Archive
Copy-Item -Path $Archive -Destination C:\test\allarchivefiles
Move-Item -Path $Archive -Destination C:\test2
Remove-Item -Path c:\test\import\* -include *.csv

Also removed the pauses, not sure what they were for apart from slowing the script down.还删除了暂停,除了减慢脚本速度之外不确定它们的用途。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM