1

実行中のバッチ ファイルから別のファイル出力を作成したいと考えています。つまり、生のコンテンツがその中にあります。このバッチ ファイル内では、「end」またはコンテンツの最後に追加した一意の単語が見つかるまで、while または for ループが実行されます。

情報が公開されるため、(重要なコンテンツを含む) ファイルを単純にコピーしたくありません。次に、バッチ経由でファイルを呼び出して実行します。

code:
-start of batch
-check if the file a.txt exist del a.txt
-starts to create the a.txt file

>start of content:
>"the quick brown fox jump over the lazy dog"
>lynx: unique word
>end of content

-writes the content to a.txt using for loop or while until it finds the unique word
-runs the a.txt file
-deletes the a.txt file
-exit

誰かが助けてくれることを願っています。ありがとうございました!または、誰かがそれを行うためのより良い方法を提案できる場合. 私はそれをお願い申し上げます

4

2 に答える 2

0
@echo off
setlocal enabledelayedexpansion
if exist a.txt del a.txt

copy nul a.txt > nul                      & :: Not needed, but in your specs

set line[1]=This is what you asked for.
set line[2]=Not really the best method.
set line[3]=But it will work.
set line[4]=
set line[5]=linux
set line[6]=[end]

for /l %%i in (1,1,1000) do (
  if     "!line[%%i]!"=="linux" goto :end
  if     "!line[%%i]!"=="[end]" goto :end
  if     "!line[%%i]!"=="" echo.>>a.txt
  if NOT "!line[%%i]!"=="" echo !line[%%i]!>>a.txt
)

:end
:: Broken Out Of Loop

ren a.txt a.bat
call a.bat
del a.bat

このline[n]方法を使用するとメモリがかなり浪費されるため、あるファイルから別のファイルにデータを移動することをお勧めします。

于 2012-09-27T07:30:51.090 に答える
0

forコマンド自体の行には引用符が必要です。

forループは、引用符を含む行に到達するまで正常に機能し、その後、すべてがカスタードに変わります...

ここからフォームにアクセスすることはできません。

代わりにvbscriptを試してみませんか?

于 2012-09-27T03:39:20.037 に答える