试图传递文件名在文件夹中以运行可执行文件

问题描述 投票:0回答:1

我有一个文件夹,其中包含一组文件,它们的名称类似于07777123456-02071234567.dat

我需要对文件夹中的每个文件运行可执行文件,如下所示:myexecutable.exe -orignum=07777123456 -destnum=02071234567 -file=07777123456-02071234567.dat

我最近的尝试是这样的:

$fileDirectory = "c:\PS";
foreach($file in Get-ChildItem $fileDirectory)
{
    Write-Output "Processing: $file"
    $phonenumbers = $file.split("-")
    Write-Output "Originating Number: $phonenumbers[0]"
    Write-Output "Destination Number: $phonenumbers[1]" 
}
#myexecutable.exe -orignum=$phonenumber[0] -destnum=$phonenumber[1] -file=07777123456-02071234567.dat

我尝试了Get-ChildItemFile-Split等的各种组合。我不断收到类似的错误:

方法调用失败,因为[System.IO.FileInfo]不包含名为'split'的方法。

有任何建议解决此问题吗?

powershell for-loop split filenames
1个回答
0
投票

好吧,我知道了。必须终于醒了。

© www.soinside.com 2019 - 2024. All rights reserved.