簡體   English   中英

在批處理代碼中創建內容所在的文件

[英]Creating a file where content is in a batch code

我想從正在運行的批處理文件中創建另一個文件輸出,這意味着原始內容在其中。 在此批處理文件中,它將執行一會兒或for循環,直到找到“ end”或我在內容末尾添加的任何唯一單詞。

我不想簡單地復制文件(其中包含重要內容),因為這將暴露信息。 然后通過批量調用文件來運行它。

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

希望有人能幫忙。 謝謝! 或者,如果有人可以建議一種更好的方法。 我會很感激

for命令本身的行將需要用引號引起來。

對於循環,在它們碰到包含引號的行之前,它們可以正常工作,然后一切都變成乳蛋糕……

您無法在此處到達那里的表格。

也許嘗試使用vbscript代替?

@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]方法相當浪費內存,我建議將數據從一個文件移動到另一個文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM