gpt4 book ai didi

powershell - 压缩存档错误: Cannot access the file because it is being used by another process

转载 作者:行者123 更新时间:2023-12-02 20:25:42 26 4
gpt4 key购买 nike

我想压缩一个路径(其中运行一个服务窗口)。

当服务停止时,它工作正常,当服务运行时,我有异常(exception):

The process cannot access the file because it is being used by another process.

但是,当我使用 7-zip 压缩时,没有任何异常。

我的命令:

Compress-Archive [PATH] -CompressionLevel Optimal -DestinationPath("[DEST_PATH]") -Force

您是否有想法在没有此异常的情况下执行任务?

最佳答案

Copy-Item 允许您访问正在另一个进程中使用的文件。

这是我最终在代码中使用的解决方案:

Copy-Item -Path "C:\Temp\somefolder" -Force -PassThru | 
Get-ChildItem |
Compress-Archive -DestinationPath "C:\Temp\somefolder.zip"

这个想法是,您通过管道传递所有复制的项目,而不必在压缩之前先将它们复制到特定目标。

我喜欢压缩文件夹的内容而不是文件夹本身,因此我在最后一行压缩之前使用 Get-ChildItem

子文件夹已包含在内。无需在第一行使用 -recurse 来执行此操作

关于powershell - 压缩存档错误: Cannot access the file because it is being used by another process,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47262348/

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