我正在尝试使用带有自定义命令(例如“删除”作为“ Del”命令等)的批处理文件来制作自己的命令提示符...但是当我遇到用户输入时,我遇到了问题,在这里是:
CMD.bat
@echo off
echo.
set /p inp=Command:
if /i %inp% == Remove ...
...
然后我停下来思考,“我将如何执行删除命令?”。因此,我要执行的操作是使用“删除”命令来像“删除C:\ Users \ usr \ Desktop \ File.txt”这样使用它,但是如果用户键入了诸如“删除blablabla”之类的其他内容,程序将如何检测到该命令语法不正确?。
因此,如果有人找到了解决方案,我将非常感激,谢谢!
答案 0 :(得分:0)
假设您要询问如何设置自定义命令,请尝试此操作。
@echo off
set "RESPONSE="
goto 'input'
: 'input'
set /p response=What would you like to do?
if /I %response%==help goto 'help'
set /p responsetwo=What would you like to %response%?
if /I %response%==remove set response=del
if /I %response%==check set response=dir
if /I %response%==dir %response% "%responsetwo%"
%response% %responsetwo%
echo %response% "%responsetwo%"
goto 'input'
: 'help'
cls
echo Check = Dir in regular command prompt, checks a directory.
echo Remove = del in regular command prompt, deletes something.
pause
goto 'input'
要添加更多自定义命令,只需添加
if /I %response%==<word you want to do X command> set response=<X command>
(显然,用第二个代码段的命令替换X。)
编辑:好的,所以在阅读您的评论后,我想出了一个更好的解决方案。来啦!
@echo off
goto 'input'
: 'input'
cls
set "response="
set /p response=What would you like to do?
set firstresponse=%response:~0,5%
if %firstresponse%==help goto 'help'
pause
if /I %firstresponse%==check set firstresponse=dir && set executeparttwo=%response:~5%
if /I %firstresponse%==remov goto 'remove'
rem Put "if /I %firstresponse%==<whatever the first 5 letters of the command would be> goto '<command name>'
%firstresponse%%executeparttwo%
pause
goto 'input'
: 'remove'
set "firstresponse=" && set firstresponse=%response:~0,6%
if /I %firstresponse%==remove set firstresponse=del
set executeparttwo=%response:~6%
%firstresponse%%executeparttwo%
pause
goto 'input'
: 'help'
cls
echo Check = Dir in regular command prompt, checks a directory.
echo Remove = del in regular command prompt, deletes something.
pause
goto 'input'
答案 1 :(得分:0)
使用doskey命令在这里输入
doskey del=remove