powershell - 如何在 PowerShell 中为多个文件运行命令
问题描述
我有一个包含图像的文件夹,我需要使用 ImageMagick 转换它们。如何在 Powershell 中为每个文件(作为参数)运行命令?
解决方案
返回一个FileInfoGet-ChildItem
对象数组,您不应将它们视为包含路径和文件名的简单字符串。
相反,使用这些对象的属性和FullName
Name
Get-ChildItem -Path "C:\Pictres" -File | ForEach-Object {
# The automatic variable '$_' or '$PSItem' contains the current object in the PowerShell pipeline.
$originalImage = $_.FullName
$convertedImage = Join-Path -Path $_.DirectoryName -ChildPath ('test_{0}' -f $_.Name)
& 'C:\INSTALL\ImageMagick-7.0.8-Q16\magick.exe' "$originalImage" -negate "$convertedImage"
}
推荐阅读
- node.js - 使用 fluent-ffmpeg 时出现间歇性像素格式错误
- dart - Flutter StreamBuilder 类型为超类
- php - 我无法更改 plesk 中的 php 设置
- asp.net-core - Ajax 发布到 ASP .NET 2.2 Razor 页面出现 404 错误
- python-3.x - 如果该行是由变量设置的,有没有办法从文本小部件中获取一行文本?
- java - 即使满足两个输出的标准,您如何确保只使用一个输出?
- python - 如何在json中返回传递的变量url参数
- azure-cosmosdb - Cosmos DB 在本地的一致性保证
- javascript - 如何将↵替换为\n
- terminal - 如何在 Visual Studio 2017 / 2019 中获取终端窗口?