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

查看:38
本文介绍了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-Zip 脚本

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

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