Powershell为文件夹中的每个文件创建一个zip(或7z),然后删除原始文件 [英] Powershell to Create a zip (or 7z) of each file in a folder then delete original file

查看:187
本文介绍了Powershell为文件夹中的每个文件创建一个zip(或7z),然后删除原始文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带iso图片吨的文件夹。我发现许多图像中都有伪数据,无法达到原始DVD的大小。通过压缩它们,我可以节省大量空间。我尝试创建一个批处理文件,但无法正常工作。

I have a folder with a Ton of iso images. I've found that a lot of the images have dummy data in them to reach the size of the original DVD. I can save an enormous amount of space by zipping them up. I tried creating a batch file but it failed to work properly.

因此,我基本上希望它为文件夹中的每个文件创建一个.7z,然后删除原始文件。

So, I basically want it to create a .7z for each file in a folder, then delete the original file.

这就是我得到的。它压缩文件,但之后无法将其移除。无法找出原因:

Here's what I got. It zips the files but it fails on removable of the files afterwards. Can't figure out why:

function zipFiles()
 {
 dir *.iso| ForEach-Object { & "7z.exe" a -mx9 $_.BaseName $_.Name } 
 }

function delFiles()
 {
 dir *.iso| ForEach-Object { & Remove-Item $_.BaseName $_.Name } 
 }

zipFiles
delFiles


推荐答案

我认为这里是一个解决方案:

I think a solution is here:

超级用户-7则脚本压缩后删除

这篇关于Powershell为文件夹中的每个文件创建一个zip(或7z),然后删除原始文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆