如何在 powershell 中将文件属性与整个数组进行匹配

发布于 2024-12-18 15:00:00 字数 377 浏览 0 评论 0原文

我有疑问和问题。

我有一个包含 600,000 个 FLV 文件的列表,这些是我想要保留的视频。
我有一个包含 500 万个 FLV 文件的文件夹,我想删除大约 440 万个不需要的文件。

我已经研究这个问题几个小时了,但考虑到数组是不可变的,找不到任何简单的东西。

我正在考虑这样做:
对于 600 万个文件夹列表中的每个文件,检查名称属性是否与我想要保留的文件数组中的任何项目匹配(使用 import-csv),并且日期是否超过 30 天。

日期部分很简单,但我不确定如何将名称与数组进行比较。它真的像引用整个数组一样简单吗?我不确定 powershell 会做什么。我将继续尝试这样做,但我将感谢任何人提供有关如何执行此操作或更好的替代方案的帮助/意见。

I have question and a problem.

I have a list of 600,000 FLV files, which are the videos I want to keep.
I have a folder of 5 million FLV files, and I want to delete the 4.4 million or so that I do not need.

I've been playing with this problem for hours but cant find anything easy considering arrays are immutable.

I was thinking of doing:
foreach file in the 6 million folder list, check to see if the name property matches any item in the array of files I want to keep (using import-csv) AND if the date is more than 30 days old.

The date part is easy, but I am not sure how to compare the name against the array. Is it really as easy as just referencing the entire array? I'm not sure what powershell would do. I will be continuing to try to do this but I would appreciate anyone's help / input on how to do this or a better alternative.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看透却不说透 2024-12-25 15:00:00

使用 PowerShell,如果您有一个文件的文件名保留在 C:\MyPath\MyFile.txt 并且这些文件位于 C:\FLVLocation\ ,则类似这样的操作会起作用。

$keep = Get-Content C:\MyPath\MyFile.txt
Get-ChildItem C:\FLVLocation| 
    where{$keep -notcontains $_.Name -and $_.CreationTime -lt [DateTime]::Now.Date.AddDays(-30)}| 
    Remove-Item

但请先测试一下。

With PowerShell, if you have a file with the filenames to keep at C:\MyPath\MyFile.txt and the files are at C:\FLVLocation\ something like this would work.

$keep = Get-Content C:\MyPath\MyFile.txt
Get-ChildItem C:\FLVLocation| 
    where{$keep -notcontains $_.Name -and $_.CreationTime -lt [DateTime]::Now.Date.AddDays(-30)}| 
    Remove-Item

But please, test first.

天煞孤星 2024-12-25 15:00:00

您能否不移动所有要保留的文件?

遍历数组中的所有文件,如果数据正常,则将文件移动到“keep”文件夹。删除其余部分,然后将文件从“keep”文件夹移回。

首先进行“试运行”可能会很好。

Can you not instead move all the files you want to keep.

Iterate over all the files in the array and if the dat is ok, move the file to a "keep" folder. Delete the rest and then move the files back from the "keep" folder.

Probably good to do a "dry run" first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文