在目录上以递归方式使用PowerShell运行简单命令 [英] Run a simple command using PowerShell recursively on a directory
问题描述
使用DOS脚本或PowerShell在目录及其所有子目录上运行此简单命令的最快方法是什么:
What's the fastest way using either DOS scripting or PowerShell to run this simple command on a directory and all its subdirectories:
convert filename.jpg -resize 620x620 "R:\processed\filename.jpg"
单个目录的DOS批处理脚本:
FOR %%a in (*.jpg) DO convert %%a -resize 620x620 "R:\processed\%%a"
我想运行这个递归地在目录结构上并使输出与输入层次结构匹配。我认为PowerShell是最简单的方法,但我无法在5分钟内学习PowerShell我必须完成这项任务!
I want to run this recursively on a directory structure and have the output match the input hierarchy. I figured PowerShell was the easiest way, but I was unable to learn PowerShell in the 5 minutes I have to do this task!
注意:不是它相关,而是 convert
来自 ImageMagick 。
Note: not that it's relevant, but convert
is from ImageMagick.
推荐答案
在PowerShell中:
In PowerShell:
使用-recurse开关和管道进行foreach 。例如:
Use the -recurse switch and pipe to foreach. For e.g.:
dir -recurse -include *.jpg | %{convert $_.FullName -resize 620x620 "R:\processed\$_"}
(请注意,%符号是foreach-object的别名)。
(Note that the % sign is an alias of foreach-object).
这篇关于在目录上以递归方式使用PowerShell运行简单命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!