PS脚本以处理数千个zip文件…
好的,所以我很新 - 目前学习Python和Powershell,但是我有问题,并且正在尝试用代码解决它。
我需要一个脚本,该脚本会
- 查看一个文件夹才能找到.zip文件
- UNZIP的文件(我可以定义的任何目的地)
- 删除已完成的zip。
- 重复步骤1-3,直到目标中没有更多的zip文件,
我尝试在PowerShell中编写一个简单的循环,而我不知道如何使Arvent-Archive进行合作。当我将 *.. zip通配符用于路径或文字路径时,我将其指向多个文件会发疯。
目的地有成千上万个文件,而且它们并不小,因此手工拉链将非常耗时,并且命名ZIP文件所谓的五千次的路径只会减少耗时的时间。
Okay, so I am very new - learning Python and PowerShell currently, but I have a problem and am trying to solve it with code.
I need a script that will
- Look at a folder to find .zip files
- Unzip located file (to whatever destination, I can define that)
- Delete the completed zip.
- Repeat steps 1-3 until there are no more zip files in the destination
I tried to write a simple loop in PowerShell and I couldn’t figure out how to get Expand-Archive to cooperate. When I used the *.zip wildcard for the path or literal path, it would get mad that I am pointing it at multiple files.
There are thousands of files at the destination, and they are not small so unzipping by hand would be extremely time consuming, and naming the path exactly what the zip file is called five thousand times would only be slightly less time consuming.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Get-Childitem将行不通。这是因为它必须在开始运行任何操作之前构建列表。通过构建列表,它必须将所有项目放入内存中,然后可以应用过滤器或执行其他操作。
如果您期望与大量物品进行运行,则需要使用.NET调用:
[system.io.directory] :: getfiles()
get-childitem vs。 .NET Framework的[System.IO.Directory] :: getFiles()带有UNC路径的方法
这些呼叫在管道“ |”时使用其他命令将将项目列表流到命令中,并允许您更快地在文件上运行一堆过滤器。您仍然需要弄清楚一些事情。
我使用7ZIP命令做与您现在所描述的类似的事情:
https ://jasonduffett.net/post/5103879646/ususion-7zip-from-powershell#:〜:text = text =一个%20STODATION%20IS%20TO%20TO%20USE%20 the%20ExCellent%207-zip,-path%20%20%20%20%28Split-Path %20-父母%20%24MyInvocation.myCommand.Definition%29%20-ChildPath%20%227Z.EXE%22%20IF%20%28%21
Get-ChildItem will not work. This is because it has to build the list before it can start running any actions. By building the list, it has to put all of the items in memory, then it can apply filters or perform additional actions.
If you are expecting to run it against a large amount of items, you need to use a .net call:
[System.IO.Directory]::GetFiles()
Get-ChildItem vs. direct use of the .NET Framework's [System.IO.Directory]::GetFiles() method with UNC paths
These calls, when piped "|" with other commands will stream the list of items to the commands and allow you to run a bunch of filters on files much more quickly. There are still a few things you will need to figure out.
I used 7zip commands to do something similar as to what you are describing now:
https://jasonduffett.net/post/5103879646/using-7zip-from-powershell#:~:text=One%20solution%20is%20to%20use%20the%20excellent%207-zip,-Path%20%28Split-Path%20-parent%20%24MyInvocation.MyCommand.Definition%29%20-ChildPath%20%227z.exe%22%20if%20%28%21