通过 Powershell 进行智能图像搜索
我对按自定义属性搜索文件感兴趣。例如,我想查找具有特定尺寸的所有 JPEG 图像。 我怀疑
Get-ChildItem -Path C:\ -Filter *.jpg -Recursive | where-object { $_.Dimension -eq '1024x768' }
这与 System.Drawing 的使用有关。怎样才能做到呢? 提前致谢
I am interested in file searching by custom properties. For example, I want to find all JPEG-images with certain dimensions. Something looks like
Get-ChildItem -Path C:\ -Filter *.jpg -Recursive | where-object { $_.Dimension -eq '1024x768' }
I suspect it's about using of System.Drawing. How it can be done?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这实际上很容易做到,而且您对 System.Drawing 的直觉实际上是正确的:
将其另存为路径中的某处
Get-Image.ps1
,然后就可以使用它了。另一种选择是将以下内容添加到您的
$profile
: 中,其工作原理几乎相同。当然,添加一些你认为合适的花哨的东西,比如文档等。
然后您可以像这样使用它:
请注意,您应该在使用后处理以这种方式创建的对象。
当然,您可以添加自定义
Dimension
属性,以便您可以进行过滤:That's actually pretty easy to do and your gut feeling about System.Drawing was in fact correct:
Save that as
Get-Image.ps1
somewhere in your path and then you can use it.Another option would be to add the following to your
$profile
:which works pretty much the same. Of course, add fancy things like documentation or so as you see fit.
You can then use it like so:
Note that you should dispose the objects created this way after using them.
Of course, you can add a custom
Dimension
property so you could filter for that:这是一种(几乎)单行的替代实现:
如果您需要多次运行此命令,我建议 Johannes 的更完整的解决方案。
Here's an alternative implementation as a (almost) one-liner:
If you are going to need to run this command more than once, I would recommend Johannes' more complete solution instead.