我目前有一个批处理文件,它通过一个文本文件并将每一行分配到一个数组中。我想循环遍历循环并从数组中的每个值中删除一定数量的字符。这可能吗?
@ECHO off
findstr /C:"number" /C:"type" testFile.txt > oneresult.txt
set "file=oneresult.txt"
set /A i=0
timeout /t 1
echo ---------------Results--------------- > results.txt
for /f "tokens=*" %%x in (oneresult.txt) do (
call echo %%x >> results.txt
call set array[%i%]=%%x
set /A i+=1
)
call echo %i% files received >> results.txt
del "oneresult.txt"
现在它只是从testFile.txt中打印检索到的字符串,然后最终将它们放入result.txt中。我希望testFile.txt中的所有字符串都删除前10个字符。如果有更简单的方法请告诉我。到目前为止,这是我发现的,但我也是一个批量菜鸟。
在没有阵列的情况下想出来,并为将来可能会搜索的其他人发布答案:
@ECHO off
findstr /C:"number" /C:"type" testFile.txt > oneresult.txt
set /A i=0
timeout /t 1
echo ---------------Results--------------- > results.txt
for /f "tokens=*" %%x in (oneresult.txt) do (
setlocal enabledelayedexpansion
call set print=%%x
call set newprint=!print:~32!
call echo !newprint! >>results.txt
endlocal
set /A i+=1
)
call echo %i% files received >> results.txt
del "oneresult.txt"
答案 0 :(得分:0)
pseudo calls
通常用于不需要setlocal enabledelayedexpansion
的不同类型的延迟扩展,而是将百分号加倍。@ECHO off
set /A i=0
(
echo ---------------Results---------------
for /f "tokens=*" %%x in (
'findstr /C:"number" /C:"type" testFile.txt'
) do (
set print=%%x
call echo:%%print:~32%%
set /A i+=1
)
call echo %%i%% files received
) > results.txt
以下代码setlocal enabledelayedexpansion
功能相同
@ECHO off&Setlocal EnabledelayedExpansion
set /A i=0
(
echo ---------------Results---------------
for /f "tokens=*" %%x in (
'findstr /C:"number" /C:"type" testFile.txt'
) do (
set print=%%x
echo:!print:~32!
set /A i+=1
)
echo !i! files received
) > results.txt