运行 递归文件夹中的一个 exe
Running an exe in recursive folders
Set-ExecutionPolicy Unrestricted
$start_path ="D:\VST\"
$start_path> Get-ChildItem-Recurse |
foreach { cd $_.DirectoryName; "VST_Screenshot_Tool"; cd ..; }
这应该 运行 VST_Screenshot_Tool.exe
在根文件夹和 $start_path
的所有子文件夹中。我收到此错误:
Expressions are only allowed as the first element of a pipeline.
At C:\Users\pithy\Desktop\screenshotter.ps1:2 char:13
+ $start_path <<<< ="D:\ZZ_AUDIO\VST etc\__ARCHIVE\*" |
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline
任何指点将不胜感激。
$start_path> Get-ChildItem-Recurse
会将字符串 D:\VST\
写入当前目录中的文件 Get-ChildItem-Recurse
。此外,您需要调用运算符 (&
) 来执行命令字符串,如果您想要 运行 外部命令,则应包括扩展名。如果没有运算符,PowerShell 将简单地回显字符串。
将您的代码更改为:
$start_path = 'D:\VST'
Get-ChildItem $start_path -Recurse -Directory | ForEach-Object {
Set-Location $_.FullName
& "VST_Screenshot_Tool.exe"
}
在 PowerShell v2 和更早版本上,您需要像这样替换 -Directory
参数:
Get-ChildItem $start_path -Recurse | Where-Object {
$_.PSIsContainer
} | ForEach-Object {
Set-Location $_.FullName
& "VST_Screenshot_Tool.exe"
}
Set-ExecutionPolicy Unrestricted
$start_path ="D:\VST\"
$start_path> Get-ChildItem-Recurse |
foreach { cd $_.DirectoryName; "VST_Screenshot_Tool"; cd ..; }
这应该 运行 VST_Screenshot_Tool.exe
在根文件夹和 $start_path
的所有子文件夹中。我收到此错误:
Expressions are only allowed as the first element of a pipeline.
At C:\Users\pithy\Desktop\screenshotter.ps1:2 char:13
+ $start_path <<<< ="D:\ZZ_AUDIO\VST etc\__ARCHIVE\*" |
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline
任何指点将不胜感激。
$start_path> Get-ChildItem-Recurse
会将字符串 D:\VST\
写入当前目录中的文件 Get-ChildItem-Recurse
。此外,您需要调用运算符 (&
) 来执行命令字符串,如果您想要 运行 外部命令,则应包括扩展名。如果没有运算符,PowerShell 将简单地回显字符串。
将您的代码更改为:
$start_path = 'D:\VST'
Get-ChildItem $start_path -Recurse -Directory | ForEach-Object {
Set-Location $_.FullName
& "VST_Screenshot_Tool.exe"
}
在 PowerShell v2 和更早版本上,您需要像这样替换 -Directory
参数:
Get-ChildItem $start_path -Recurse | Where-Object {
$_.PSIsContainer
} | ForEach-Object {
Set-Location $_.FullName
& "VST_Screenshot_Tool.exe"
}