PoshRSJob 循环遍历文件目录

我自己

我试图遍历一个目录(按最小文件排序),获取路径和文件名,然后将这些结果泵入一个实用程序.exe 程序。

我正在尝试使用 PoshRSJob 进行多线程处理,但我什至没有看到实用程序出现在任务管理器中,我收到错误“哈希文字中不允许使用空键。”,对于每个存在的文件(如果目录中有 50 个文件,那么我会收到 50 个错误)。我也无法测试节流是否有效,因为实际上没有任何东西在运行。

Import-Module C:\PoshRSJob.psm1
Function MultiThread($SourcePath,$DestinationPath,$CommandArg, $MaxThreads){
    if($CommandArg -eq "import") {
        $fileExt = "txt"
    }else{
        $fileExt = "ini"
    }
    $ScriptBlock = {
        Param($outfile, $cmdType, $fileExtension)
        [pscustomobject] @{
            #get the full path
            $filepath = $_.fullname     
            #get file name (minus extension)
            $filename = $_.basename
            #build output directory
            $destinationFile = "$($outfile)\$($filename).$($fileExtension)"
            #command to run
            $null = .\utility.exe $cmdType -source `"$filepath`" -target `"$destinationFile`"
        }
    }
    #get the object of the passed source directory, and pipe it into start-rsjob
    Get-ChildItem $SourcePath | Sort-Object length | Start-RSJob -ScriptBlock $ScriptBlock -ArgumentList $DestinationPath, $CommandArg, $fileExt -Throttle $MaxThreads

    Wait-RSJob -ShowProgress | Receive-RSJob
    Get-RSJob | Receive-RSJob
}
MultiThread "D:\input" "D:\output" "import" 3
Frode F.

您的脚本块正在创建一个您定义$null = .\utility.exe +++为属性的对象正如它所说,$null(nothing) 的值不能是属性名称.. 我建议只运行这些行..

您可能还想更改Wait-RSJob-part。您没有指定工作,因此它永远不会等待任何事情。尝试:

尝试将脚本块更改为:

Import-Module C:\PoshRSJob.psm1
Function MultiThread($SourcePath,$DestinationPath,$CommandArg, $MaxThreads){
    if($CommandArg -eq "import") {
        $fileExt = "txt"
    }else{
        $fileExt = "ini"
    }

    $ScriptBlock = {
        Param($outfile, $cmdType, $fileExtension)
        #get the full path
        $filepath = $_.fullname     
        #get file name (minus extension)
        $filename = $_.basename
        #build output directory
        $destinationFile = "$($outfile)\$($filename).$($fileExtension)"
        #command to run
        $null = .\utility.exe $cmdType -source `"$filepath`" -target `"$destinationFile`"
    }

    #get the object of the passed source directory, and pipe it into start-rsjob
    Get-ChildItem $SourcePath | Sort-Object length | Start-RSJob -ScriptBlock $ScriptBlock -ArgumentList $DestinationPath, $CommandArg, $fileExt -Throttle $MaxThreads

    Get-RSJob | Wait-RSJob -ShowProgress | Receive-RSJob
}
MultiThread "D:\input" "D:\output" "import" 3

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

循环遍历目录中的文件

带有 Executionpolicy RemoteSigned 的导入模块 PoshRSJob

循环遍历目录中的每个 PDF 文件

循环遍历目录中给定类型的文件

循环遍历两个目录并访问循环外的文件

循环遍历 bash 主目录中的某些文件行

Bash循环遍历包含隐藏文件的目录

循环遍历子目录中的json文件

使用“ for”循环遍历目录中的所有文件

循环遍历文件路径以检查目录是否存在

循环遍历vb中所有目录中的文件

循环遍历多个目录中的每个文件并应用MergeSamFiles

循环遍历文件中的行并创建多个目录

For循环遍历目录树,从同名文件中提取结果

循环遍历目录中的每个文件并将输出写入文本

如何使此脚本循环遍历目录中的所有文件?

遍历目录的文件

Python For循环不遍历目录

PHP 循环遍历嵌套目录

以目录名称中的日期为条件循环遍历目录中的文件(Mac os - zsh)

循环遍历目录中的所有.sh文件以在每个目录中查找特定文本

For循环遍历文件

循环遍历文件列表

循环遍历目录中的文件,并比较最新的 2 个文件是否有重复项

循环遍历目录中的前 12 个文件,如果找到文件则中断

循环遍历目录/文件夹中的文件,过滤它们,然后逐行从中读取信息

使用if语句(批处理文件)循环遍历目录中的文件

循环遍历目录中的子文件夹并从 .CSV 文件导入指定的列

批处理文件循环遍历目录,并基于每个文件创建变量