每行循环-尝试过的PS和CMD

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

[好,我的问题是我的脚本每回合仅解析列表的第一行,所涉及的程序没有批处理支持,因此需要为每行开始。如果有人甚至可以解释我做错了,那就太好了

@echo off

SETLOCAL ENABLEDELAYEDEXPANSION
SET count=1

FOR /F "tokens=* USEBACKQ" %%F IN (`cd /d J:\temp\2 ^& dir /p /b /s`) DO (
SET var=%%F
)
ECHO %var%

IF not exist "J:\temp\1\%var:~3%" (mkdir "J:\temp\1\%var:~3%")
RMDIR /s /q "J:\temp\1\%var:~3%\"

FOR /F "tokens=* USEBACKQ" %%A in ( %var% ) DO (
SET count+=1
J:\temp\windows\comp.exe -o"J:\temp\1\%var:~3%" -cn -d10 -intense -brute -s125 -t-j "%var%" )

这也不起作用

@echo off

SETLOCAL ENABLEDELAYEDEXPANSION
set /a count = 1

FOR /F "tokens=* USEBACKQ" %%F IN (`cd /d J:\temp\2 ^& dir /p /b /s`) DO (
SET var=%%F
)
ECHO %var%

IF not exist "J:\temp\1\%var:~3%" (mkdir "J:\temp\1\%var:~3%")
rmdir /s /q "J:\temp\1\%var:~3%\"

for /F "tokens=* USEBACKQ" %%A in ( %var% ) do (
SET /a count+=1
echo !count!
J:\temp\windows\precomp.exe -o"J:\temp\1\%var:~3%" -cn -d10 -intense -brute -s125 -t-j "%var%" )

[尝试过Powershell,小得多但没有运气。 powershell认为路径会很长,但没有

$file = (Get-ChildItem "J:\temp\2" -Recurse -Force -ErrorAction SilentlyContinue ).fullname
$fout = (Get-ChildItem "J:\temp\2" -Recurse -Force -ErrorAction SilentlyContinue ).fullname.Substring(10)

Robocopy "J:\temp\2" "J:\temp\1\" /S /E /ZB /DCOPY:T /SEC /COPYALL /XC /XO /XF *.*

Get-Content (Get-ChildItem "J:\temp\2" -Recurse -Force -ErrorAction SilentlyContinue ).fullname | ForEach-Object {
J:\temp\windows\precomp.exe -o"J:\temp\1\$fout" -cn -d10 -intense -brute -s125 -t-j "$file"
}

[也Powerrshell:如果我使用Get-Content,则会收到错误消息,拒绝访问路径,或者使用Get-ChildItem突然显示错误的路径,如果手动匹配,则会出现错误“” ReadLines“和” 1“参数(s)”,因此它不再逐行解析

$file = @(Get-ChildItem "J:\temp\2\" -Recurse -Force -ErrorAction SilentlyContinue ).fullname
$fout = (Get-ChildItem "J:\temp\2\" -Recurse -Force -ErrorAction SilentlyContinue ).fullname.Substring(10)

Robocopy "J:\temp\2" "J:\temp\1\" /S /E /ZB /DCOPY:T /SEC /COPYALL /XC /XO /XF *.*

$arrayFromFile = @(Get-Content $file)
$arrayFromFout = @(Get-Content $fout)

foreach($line in [System.IO.File]::ReadLines("$arrayFromFile"))
{
       J:\temp\windows\precomp.exe -o"J:\temp\1\$_arrayFromFout" -cn -d10 -intense -brute -s125 -t-j "$_arrayFromFile"
}
bash powershell loops parsing
2个回答
0
投票

最后不了解您在foreach循环中所做的事情。您从J:\ temp \ 2中获取所有数据,但不对其进行任何处理。要使用此数据,必须在foreach中使用$ _变量。

 Get-Content (Get-ChildItem "J:\temp\2" -Recurse -Force -ErrorAction SilentlyContinue ).fullname | ForEach-Object {
    J:\temp\windows\precomp.exe -o"J:\temp\1\$fout" -cn -d10 -intense -brute -s125 -t-j "$file"
    }

0
投票

现在可以使用:

Robocopy "J:\temp\2" "J:\temp\1\temp\2\" /E /ZB /DCOPY:A /SEC /COPYALL /XC /XO /XF *.*

(Get-ChildItem "J:\temp\2\" -Recurse -Attributes !D -Force -ErrorAction SilentlyContinue ).fullname | Out-File -FilePath .\Process.txt

foreach($file in [System.IO.File]::ReadLines(".\Process.txt"))
{       
    $path = "J:\temp\1" + $file.Substring(2)
    J:\temp\windows\precomp.exe -o"$path" -cn -d10 -intense -brute -s125 -t-j $file
}

似乎不使用外部文件是不可能的

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