为什么findstr什么也不返回?

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

我正在执行批处理脚本,以对不同目录中的文件进行findstr迭代,但是我什么也不返回。我确定该字符串存在于所有文件中。

这是我的脚本


setlocal

rem Iterate each folder in the current directory.
for /d %%A in (*) do (

    rem Check if orca_input subfolder exist.
    if exist "\orca_input\%%~A" (

        rem Check if dft_opt.log files exist.
        if exist "\orca_input\%%~A\dft_opt.log" (

            rem Change working directory to where the files are temporarily.
            pushd "\orca_input\%%~A" && (

                rem Run the program.
                findstr /C:"Last Energy change" dft_opt.log > energychange.dat
                popd
            )
        )
    )
)

我看不到错误。谢谢大家。

编辑:我按照建议尝试了此脚本,但未创建文件.dat

    setlocal

rem Iterate each folder in the current directory.
for /d %%A in (*) do (

            rem Check if dft_opt.log files exist.
        if exist "\orca_input\%%~A\dft_opt.log" (

            rem Change working directory to where the files are temporarily.


                rem Run the program.
                findstr /C:"Last Energy change" "\orca_input\%%~A\dft_opt.log" >"\orca_input\%%~A\energychange.dat"
            )
        )
    )
)
cmd foreach findstr
1个回答
0
投票

让我们尝试一下:

setlocal

rem Iterate each folder in the current directory.
for /d %%A in (*) do (
   rem Check if dft_opt.log file exists.
   if exist "orca_input\%%~A\dft_opt.log" (
      findstr /C:"Last Energy change" "orca_input\%%~A\dft_opt.log">"orca_input\%%~A\energychange.dat"
   )
)

我觉得我们需要弄清楚文件夹的结构。

另一种选择:

setlocal

rem Iterate each folder in the current directory.
for /d %%A in (*) do (
   rem Check if dft_opt.log file exists.
   if exist "%%~A\orca_input\dft_opt.log" (
      findstr /C:"Last Energy change" "%%~A\orca_input\dft_opt.log">"%%~A\orca_input\energychange.dat"
   )
)
© www.soinside.com 2019 - 2024. All rights reserved.