我想创建powershell脚本来压缩文件夹中超过一周的文件,如果成功则删除原始文件 [英] I want to create powershell script to zip files older than a week in a folder and delete the original files if successful

查看:178
本文介绍了我想创建powershell脚本来压缩文件夹中超过一周的文件,如果成功则删除原始文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PowerShell脚本新手。我找到了这个 [ ^ ]有关创建zip文件夹的文章,但我不知道具体如何找到超过1周的文件。



我尝试过:



我尝试使用foreach循环并将文件复制到临时目录,然后使用我之前找到的链接,但Powershell语法无法正常工作。

解决方案

检查这个:

脚本获取超过指定时间的文件期限PowerShell [ ^ ]

删除早于x天的文件 - 清理脚本 [ ^ ]

使用PowerShell删除超过15天的文件 - Stack Overflow [ ^ ]



并根据您的需要进行更改;)


#获取中的文件列表原始文件夹


rootFolder = C:\ MyFiles \ Output

Hi, I am new to powershell scripting. I found this[^] article on creating a zip folder but I don't know how to specifically find files older than 1 week.

What I have tried:

I have tried using a foreach loop and copying the files into a temp directory and then using the link I found earlier but Powershell syntax is not working properly.

解决方案

Check this:
Script Get files older than a specified time period PowerShell[^]
Delete files older than x-days - Cleanup Script[^]
Delete files older than 15 days using PowerShell - Stack Overflow[^]

And change to your needs ;)


#get the list of files in the original folder


rootFolder = "C:\MyFiles\Output"


这篇关于我想创建powershell脚本来压缩文件夹中超过一周的文件,如果成功则删除原始文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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