gpt4 book ai didi

batch-file - windows批处理文件编程

转载 作者:行者123 更新时间:2023-12-03 10:03:13 28 4
gpt4 key购买 nike

我想在 Windows XP 中使用 dos 批处理文件编程在现有文本文件中的特定行写入一行文本。我还想输入用户的行号。任何帮助将不胜感激。

最佳答案

提示用户的例子:

:MENU

SET /P TYPE=Type the line number and press enter:
if "%TYPE%"=="1" goto ONE
if "%TYPE%"=="2" goto TWO
if "%TYPE%"=="3" goto THREE
if "%TYPE%"=="4" goto FOUR
if "%TYPE%"=="5" goto FIVE
goto MENU

注意:带L选项的FOR命令可以产生更大的交叉校验;如需更多信息,请输入 c:>FOR/?

FOR/L %variable IN (start,step,end) DO 命令[命令参数]

The set is a sequence of numbers from start to end, by step amount.
So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
generate the sequence (5 4 3 2 1)

FOR/L %%a IN (1,1,1000) DO if "%TYPE%"=="%%a"goto :VALIDNUM

@echo off
rem this only prompts the user for a number

set VALIDNUM=

:MENU
cls
echo.
echo.
If NOT "%VALIDNUM%"=="" echo the number is %VALIDNUM%
echo.

SET /P TYPE=Type a line number and press enter:

FOR /L %%a IN (1,1,1000) DO if "%TYPE%"=="%%a" set VALIDNUM=%TYPE%

goto MENU

关于batch-file - windows批处理文件编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3733657/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com