0

了解しました。これでバッチファイルの制限を押し上げていると思います。

ファイルを調べて「X」または「y」を見つけるバッチファイルが必要です。どちらかが見つかった場合は、プログラムを実行します。どちらも見つからない場合は、残りのコードを続行します。検索するファイルの拡張子は.infです。メモ帳を使って開きます。どこから始めればいいのかわからない。どんな助けでも大歓迎です。:)

4

3 に答える 3

2

FINDSTRを使用して、同時に複数のエントリを検索できます。次のように使用します。

FINDSTR "term1 term2 term3 ..."

少なくとも1つの用語が見つかった場合、結果は成功になります。必要に応じて、スイッチを使用し/Iて検索で大文字と小文字を区別しないようにします。

FINDSTR /I "term1 term2 term3 ..."

FINDSTRデフォルトで検索stdinします。入力をファイルにリダイレクトして、.infファイルを検索するようにします。

FINDSTR /I "term1 term2 term3 ..." <file.inf

または、ファイル名を別のパラメーターとして指定することもできます。

FINDSTR /I "term1 term2 term3 ..." file.inf

2つのケースでは出力が少し異なりますが、実際には出力は必要ありませんが、検索の結果、つまり成功したか失敗したかはわかります。

ERRORLEVEL結果を確認するには、次のような明示的なテストを使用できます。

FINDSTR /I "term1 term2 term3 ..." file.inf
IF NOT ERRORLEVEL 1 yourprogram.exe

これに代わる構文は、ERRORLEVEL システム変数を使用することです。これは、おそらく前者よりも簡単です。

IF %ERRORLEVEL% == 0 yourprogram.exe

Another way to do the same is to use the && operator. This method is not entirely identical to the ERRORLEVEL test, but with FINDSTR both ERRORLEVEL test and && work identically, and in this situation the && method has the advantage of being more concise:

FINDSTR /I "term1 term2 term3 ..." file.inf && yourprogram.exe

This is almost it. One final note is, since you may not be actually interested in the output of FINDSTR, you might as well want to suppress it by redirecting it to NUL, like this:

FINDSTR /I "term1 term2 term3 ..." file.inf >NUL && yourprogram.exe
于 2013-01-30T20:39:13.200 に答える
0

このページから始めてみてください:

http://www.robvanderwoude.com/findstr.php

次に、バッチファイルの基本についてさらに参照します。

http://www.robvanderwoude.com/batchfiles.php

于 2013-01-30T18:03:10.413 に答える
0

FINDとFCの組み合わせでそれを行うことができます。

@echo off
REM try to find X
FIND /c "X" file.inf >test_isxfound.txt
REM what does it look like when I don't find a match
FIND /c "th1s$tringb3tt3rn0tbeinthisfile" file.inf >test_xnotfound.txt
REM then compare those results with the results where we know it wasn't found
FC test_xnotfound.txt test_isxfound.txt
REM then check to see if FC saw a difference
IF ERRORLEVEL 1 goto xisfound

ECHO *** X is not found
goto end
:xisfound
ECHO *** X is found
goto end
:end
del test_xnotfound.txt
del test_isxfound.txt
于 2013-01-30T20:27:02.020 に答える