中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-10 16:16
47,811 topics / 349,897 posts / today 0 new / 48,255 members
DOS批处理 & 脚本技术(批处理室) » Ask: How to judge that the input variable is empty.
Printable Version  4,447 / 19
Floor1 lianjiang2004 Posted 2006-12-11 03:02
金牌会员 Posts 1,884 Credits 3,946
Ask: How to judge that the input variable is empty.

Purpose:
According to the content in set.ini such as E:\aaa1\bbb2.gho, that is, including drive letter, directory, file name, where the directory can be absent.
By separating the characters in set.ini, respectively obtain the variables of drive letter, directory, file name.
If there is no drive letter or no file name, it needs to be reset, otherwise continue.
The following is my code, please ask where is wrong? Thank you.

------------------
:sub_18d
Rem Read the settings file Set.ini
For /f "tokens=*" %%i In (c:\_set.ini) Do (
Set drive=%%~di
Set directory=%%~pi
Set filename=%%~nxi
)
If %drive%=="" Goto sub_18h
If %filename%=="" Goto sub_18h
Goto sub_18e

:sub_18h
cls
Echo.
Echo The custom path format is incorrect, and it needs to be reset [correct format such as E:\aaa1\bbb2.gho].
Echo.
pause
Goto Set

:sub_18e
Floor2 a9319751 Posted 2006-12-11 03:16
中级用户 Posts 170 Credits 439
如果 "#%drive%"=="#" 则跳转到sub_18h
如果 "#%filename%"=="#" 则跳转到sub_18h

Rem 读取设置文件Set.ini
For /f "tokens=*" %%i In (c:\_set.ini) Do (

set.ini?
_set.ini?
Floor3 ccwan Posted 2006-12-11 03:20
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
It's quite messy ^_^, by the way, the obtained path is \aaa1\.
Floor4 ccwan Posted 2006-12-11 03:43
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Try the following code:
Floor5 lianjiang2004 Posted 2006-12-11 03:53
金牌会员 Posts 1,884 Credits 3,946
Originally posted by a9319751 at 2006-12-11 03:16:
If "#%drive%"=="#" Goto sub_18h
If "#%filename%"=="#" Goto sub_18h



Rem Read configuration file Set.ini
For /f "tokens=*" %%i In (c:\_s ...

Sorry, it's _set.ini.
Floor6 lianjiang2004 Posted 2006-12-11 04:03
金牌会员 Posts 1,884 Credits 3,946
Originally posted by ccwan at 2006-12-11 03:43:
Try the following code:
Floor7 ccwan Posted 2006-12-11 05:36
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
When there is no drive letter in the path, your code will take the current drive letter. So, %drive% is never empty.
Floor8 lianjiang2004 Posted 2006-12-11 06:01
金牌会员 Posts 1,884 Credits 3,946
Originally posted by ccwan at 2006-12-11 05:36:
When there is no drive letter in the path, your code will take the current drive letter. So, %drive% is never empty.

The problem is that an empty directory is also not acceptable. For example, e:\sys.gho, which is actually saved to the root directory. I want this to be okay.
Floor9 a9319751 Posted 2006-12-11 06:10
中级用户 Posts 170 Credits 439
:
:sub_18d
Rem Read the settings file Set.ini
For /f "tokens=*" %%i In (c:\_set.ini) Do (
Set drive=%%~di
Set directory=%%~pi
Set filename=%%~nxi
)
If "%drive%"=="" Goto sub_18h
If "%filename%"=="" Goto sub_18h
Goto sub_18e

:sub_18h
cls
Echo.
Echo The custom path format is incorrect, please reset it [correct format such as E:\aaa1\bbb2.gho].
Echo.
pause
Goto Set

:sub_18e
pause
Floor10 ccwan Posted 2006-12-11 06:15
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
re a9319751:

"" is one place, but you'll know when you try. When there's no *.gho, directory=\ still doesn't work.

[ Last edited by ccwan on 2006-12-1人 at 06:17 AM ]
Floor11 a9319751 Posted 2006-12-11 06:21
中级用户 Posts 170 Credits 439
re ccwan
I tried
e:\sys.gho
e:\sys\sys.gho
e:\
All are okay

[ Last edited by a9319751 on 2006-12-11 at 06:24 AM ]
Floor12 lianjiang2004 Posted 2006-12-11 06:23
金牌会员 Posts 1,884 Credits 3,946
According to the modification of building 2, it seems okay.
-----------

:sub_18d
Rem Read the configuration file _Set.ini
For /f "tokens=*" %%i In (c:\_set.ini) Do (
Set drive=%%~di
Set directory=%%~pi
Set filename=%%~nxi
)

If "#%drive%"=="#" Goto sub_18h
If "#%filename%"=="#" Goto sub_18h
Goto sub_18e

:sub_18h
cls
Echo.
Echo The custom path format is incorrect, please reset it [The correct format is like E:\aaa1\bbb2.gho].
Echo.
pause
Goto Set_0

:sub_18e
Floor13 ccwan Posted 2006-12-11 06:29
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Then I don't understand. There's no problem with E:\aaa1\bbb2.gho here, but an error occurs when accessing E:\aaa1.
Floor14 a9319751 Posted 2006-12-11 06:35
中级用户 Posts 170 Credits 439
re ccwan
Yes, I didn't test this just now. This is an error.
Floor15 a9319751 Posted 2006-12-11 06:41
中级用户 Posts 170 Credits 439
:
:sub_18d
Rem Read the configuration file Set.ini
For /f "tokens=*" %%i In (a.txt) Do (
Set drive=%%~di
Set directory=%%~pi
Set filename=%%~nxi
If "%%~nxi"=="%%~ni" Goto sub_18h
)

If "%drive%"=="" Goto sub_18h
If "%filename%"=="" Goto sub_18h
Goto sub_18e

:sub_18h

Echo.
Echo The custom path format is incorrect, please reset it [The correct format is like E:\aaa1\bbb2.gho].
Echo.
pause
Goto Set

:sub_18e
Echo Custom
pause

Added a sentence
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023