【发布时间】:2022-07-14 22:00:03
【问题描述】:
我快疯了。我不得不承认我是一个典型的复制粘贴非脚本人员,站在这里有一些我无法解决的新问题。我想使用 ocrmypdf.exe,我必须在其中读取 PDF 的网络文件夹并将其放在子文件夹中。
ocrmypdf 工作简单:ocrmypdf.exe
我有 3 个变量,例如:
$source = @(Get-ChildItem -Path 'X:\OCR\*.pdf') # <-- here are my files, filtered for pdfs
$destname = "X:\ocr\done" #destination-folder where the pdf-files should be written in
$destfiles = foreach ($file in $source) {"$destname\$($file.name)"} # <--- destination path + the same source-file-name
当我必须在 Powershell 中运行 command-exe 时,我应该像这样运行它
Foreach ($a in $source)
{
& $command $param
}
其中 $command 和 $param 是(不是)这样的:
$command = 'ocrmypdf.exe'
$param = '$source', '$destfiles'
但我已经知道这是行不通的,因为 foreachloop 不能与我的变量一起使用。
有人可以帮我解决这个问题吗?是的,我现在懒惰地阅读一本 powershell 书,但我还是试试运气:)
提前谢谢你
【问题讨论】:
标签: powershell