用于处理输入和导出到文本文件的批处理文件

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

我需要用户输入1-20个输入并获取这些输入并在其中构建一个文件。

我有点使用不同的功能,但询问用户他们想要输入多少条目,我希望这要求用户输入他们的条目,完成后按“q”例如,这将构建文件需要。

@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
setlocal

:mainmenu
echo 1. 1 user
echo 2. 2 users
echo 3. 3 users
set selection=
set /p selection=Please choose a selection [1 - 3]:
if %selection% EQU 1 goto 1user
if %selection% EQU 2 goto 2users
if %selection% EQU 3 goto 3users
cls
goto mainmenu

:1user
set /p user1=Username 1

echo %user1%

(
echo rem Delete User Profiles after 2 days - Log activity to log.txt
echo "C:\Users\Administrator\Documents\apps\delprof2\delprof2.exe /ed:%user1% /d:2 /u /i ^>^> "C:\temp\log.txt""
echo rem Set following variable for file size in Bytes (1024 Bytes=1KB,  1024KB=1MB, 1024MB=1GB)
echo SET /A FileSize=6288
echo rem Set following variable for file extensions to check (*.* = all  files)
echo SET Filter=log.txt
echo rem Set following variable with path to check insided for files
echo SET Folder=c:\temp\
echo rem Delete the file if matches above
echo FOR /R "%Folder%" %%F IN (%Filter%) DO (
echo IF %%~zF GTR %FileSize% (
echo ECHO Deleting "%%F"
echo DEL /F "%%F"))
echo EXIT /B /0
) >> "c:\temp\testbat.txt"
timeout 10
goto mainmenu
batch-file
1个回答
0
投票

你基本上问“输入直到q”。循环非常简单:

@echo off
setlocal

set nr=1
:loop
  set /p "newuser=Enter user %nr% or [q] to quit: "
  if /i "%newuser%"=="q" set /a nr-=1 & goto :done
  set user_%nr%=%newuser%
  set /a nr+=1
goto:loop

:done
echo you entered %nr% users:
set user_
REM rest of your code

注意:LotPings是正确的:qazxsw poi:qazxsw poi代码块中的文字qazxsw poi,你必须To not prematurely ending a (code block) all closing praenthesis inside have to be escaped with a caret ^),否则它结束你的代码块(太早)。

© www.soinside.com 2019 - 2024. All rights reserved.