简体   繁体   English

Powershell使用特定文件大小的“ _lowRes.jpg”创建文件CSV

[英]Powershell Create CSV of files with “_lowRes.jpg” of a certain file size

I am trying to create a CSV file of all jpgs in a directory and its sub-directories that are above 100 KB and have the suffix "_lowRes.jpg". 我正在尝试创建目录及其子目录中所有jpgs的CSV文件,这些jpgs大于100 KB,后缀为“ _lowRes.jpg”。

Want to use Powershell. 想要使用Powershell。

Any help please? 有什么帮助吗?

This is pretty easy actually! 实际上,这很容易!

You'll do this with two separate filters, which PowerShell achieves via the Where-Object cmdlet. 您将使用两个单独的过滤器执行此操作,PowerShell通过Where-Object cmdlet实现了这些过滤器。 This cmdlet accepts comparisons in the format of {$_.PropertyName -eq "Something"} or PropertyName -eq "Something" . 此cmdlet接受{$_.PropertyName -eq "Something"}PropertyName -eq "Something"格式的比较。 The later format is only available on PowerShell v3 and up. 更高的格式仅在PowerShell v3及更高版本上可用。

First, to filter to only files above 100KB. 首先,仅过滤100KB以上的文件。

Where-Object Length -ge 100KB

The second part, where the filename contains something. 第二部分,文件名包含一些内容。

Where-object Name -like "*lowRes.jpg*"

You could join them, but I would just pipe one into the other, like this. 您可以加入他们,但我只想像这样将其中一个加入另一个。

dir *.jpg -Recurse | Where-Object Length -ge 100KB | Where-object Name -like "*lowRes.jpg*"

You might want to put the Name filtering first, because less files will have a certain name than be above or below a certain size. 您可能希望首先使用“名称”过滤,因为具有“特定名称”的文件要少于“具有特定大小”的文件。 Depends on how your files are laid out. 取决于文件的布局方式。

Finally, pipe all of that into the Export-Csv cmdlet and bam, you're done! 最后,将所有内容通过管道Export-CsvExport-Csv cmdlet和bam中,就完成了!

you can do it simply like this : 您可以像这样简单地做到:

Get-ChildItem "C:\temp" -Recurse -file -filter "*_lowRes.jpg" | 
                 Where Length -ge 100KB | select fullname, Length |
                                export-csv "c:\temp\result.csv" -NoType

short version (for no purist) : 简短版本(不适合纯粹主义者):

gci "C:\temp" -Rec -file -filter "*_lowRes.jpg" | ? L -le 100KB | select fu*, le* | epcsv "c:\temp\result.csv" -Not

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM