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

时间:2021-08-05 02:23:42

How do you check for already existing batch files in batch script? I'm working on a batch RPG game where you can log in or create an account. I have successfully been able to set up a code that notifies the user when the username has a space in it, and how it can't be used, but I'm stumped at how it could be done to check for a duplicate batch file. For example, I already have a username called "Test", and I would like to make another username called "Test"...

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

Here is a copy of my code for the no spaces script:

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

: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

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

1 个解决方案

#1


1  

To check for spaces in var:

检查var中的空格:

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

to check whether the filename var exists:

检查文件名var是否存在:

if exist %var%.ext (echo file %var%.ext exists) else (echo file %var%.ext not found)

btw - an easy-peasy game-save routine is

顺便说一句 - 一个简单易玩的游戏保存程序

set>%var%.ext

and reload is

并重新加载

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

note that var above can be any variable-name and .ext your chosen file extension.

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

#1


1  

To check for spaces in var:

检查var中的空格:

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

to check whether the filename var exists:

检查文件名var是否存在:

if exist %var%.ext (echo file %var%.ext exists) else (echo file %var%.ext not found)

btw - an easy-peasy game-save routine is

顺便说一句 - 一个简单易玩的游戏保存程序

set>%var%.ext

and reload is

并重新加载

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

note that var above can be any variable-name and .ext your chosen file extension.

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