问题描述
我有一个简单的bash命令在使用ImageMagick低流量的网站自动调整一些图片 - 我想将其转换为一个PowerShell命令,所以我没有在我的网络服务器安装Cygwin。任何人都可以在这里借给他们的PSH技能?
LS | xargs的-I {} rconvert{}调整大小128×128 \\> {}
您最好的选择是管道LS到的foreach对象的命令行开关这样的(%是的foreach对象的别名)的输出:
LS | %{rconvert $ _调整大小128×128}
编辑:LS输出的FileInfo列表或DirectoryInfo的对象到管道。为了筛选出的DirectoryInfo对象,使用where对象过滤器(?是别名):
LS | { - 不是$ _ PSIsContainer} | %{rconvert $ _调整大小128×128}
如果您需要在命令访问的全路径名,使用FileInfo对象的FullName属性(本身$ _将被解析为$ _名称这仅仅是文件名):
LS | { - 不是$ _ PSIsContainer} | %{rconvert $ _。FullName的调整大小128×128}
I've got a simple Bash command to resize some images automatically on a low-traffic website using ImageMagick - I'd like to convert this to a PowerShell command so I don't have to install Cygwin on my webserver. Can anyone lend their PSh skills here?
ls | xargs -I {} rconvert "{}" -resize 128x128\> "{}"
Your best bet is to pipe the output of ls to the foreach-object commandlet like this (% is an alias for foreach-object):
ls | %{rconvert $_ -resize 128x128}
Edit: ls outputs a list of FileInfo or DirectoryInfo objects onto the pipeline. To filter out the DirectoryInfo objects, use the where-object filter (? is alias):
ls | ?{-not $_.PSIsContainer} | %{rconvert $_ -resize 128x128}
If you need to access the full path name in your command, use the FullName property of the FileInfo object ($_ by itself will be resolved to $_.Name which is just the filename):
ls | ?{-not $_.PSIsContainer} | %{rconvert $_.FullName -resize 128x128}
这篇关于转换xargs的bash命令到PowerShell的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!