如何使批处理文件检查重复的批处理文件?

时间:2015-12-13 23:49:14

标签: windows batch-file cmd

如何在批处理脚本中检查已存在的批处理文件? 我正在进行批量RPG游戏,您可以在其中登录或创建帐户。我已经成功地设置了一个代码,当用户名中有空格时会通知用户,以及如何使用它,但我很难知道如何检查它重复的批处理文件。例如,我已经有一个名为" Test"的用户名,我想创建一个名为" Test" ...

的用户名

以下是我的无空间脚本代码的副本:

:createuser
echo.
echo What would you like your Username to be?
set /p username1= 
set v1f=0

:checkforspaces
set x=!v1f!
set Letter%v1f%=!username1:~%x%,1!
if "!Letter%v1f%!" EQU " " (
echo.
echo.
echo Sorry you cant use spaces in your Username.
pause>nul
goto entergame
)
if NOT "!Letter%v1f%!" EQU "" (
set /a v1f=%v1f%+1
goto checkforspaces
)
echo.
echo What would you like your Password to be?
set /p password1= 
goto DATA_VALUES

And here is an image of the Game:

1 个答案:

答案 0 :(得分:1)

检查var中的空格:

echo %var%|find " " >nul
if errorlevel 1 (echo no spaces) else (echo spaces found)

检查文件名var是否存在:

if exist %var%.ext (echo file %var%.ext exists) else (echo file %var%.ext not found)
顺便说一句,这是一个简单易玩的游戏保存程序

set>%var%.ext

并重新加载

for /f "delims=" %%a in (%var%.ext) do set %%a

请注意,上面的var可以是您选择的文件扩展名的任何变量名和.ext

相关问题