bash - 循环遍历每一行 - 尝试过 PS 和 CMD
问题描述
美好的一天,我的问题是我的脚本只在每一轮解析我的列表的第一行,有问题的程序没有批处理支持,所以它需要从每一行开始。如果有人能解释我做错了什么,那就太好了
@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"
}
解决方案
最后不明白你在 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"
}
推荐阅读
- java - JPA 和 Oracle 12 中的 @Lob 注释
- java - Crashlytics 如何找到崩溃的确切来源
- excel - Excel:将值向下复制一列,直到另一列中的第一个空白单元格?
- scala - 如何更新 Spark DataFrame 的架构(Dataset.withColumn 和 Datset.select 等方法在我的情况下不起作用)
- c# - asp.net .asmx 网络服务 ishow XXE 漏洞 - 外部 DNS
- html - Thymeleaf - 将 HTML 插入
- java - Hazelcast缓存中是否有类似比较和设置的东西?
- angular - 从 NgFor 加载 NgModel 时屏蔽值
- c++ - 如何使用 gcc 指定 stdcall 调用约定?
- angular - 如何限制材料输入中的特殊字符