首页 > 解决方案 > 从 foreach 中的文本文件复制

问题描述

我正在尝试复制一个文本文件(一次一行),打开记事本++,在一行上运行一个宏,然后将该文本附加到另一个文件中。它完美地运行宏,但是它完全忽略了 $changefile 中的文本,只复制了 $exportfile。这是我到目前为止所拥有的

$exportfile=$args[0]
$changefile="Changefile.txt"
$inputfile="tick-import.txt"
$wshell = New-Object -ComObject wscript.shell;


$statement = get-content $exportfile
$newstatement = get-content $changefile
Start notepad++ $changefile
foreach($line in $statement) {  

    $line | out-file -Filepath $changefile 
    Sleep 2
    $wshell.SendKeys("^%1")
    Sleep 1

    foreach($line in $newstatement) {

        $line | out-file $inputfile -Append
    }
}

第二个 foreach 是行不通的。

标签: powershellloops

解决方案


推荐阅读