China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-20 17:50
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask: How to judge that the input variable is empty. View 4,232 Replies 19
Original Poster Posted 2006-12-11 03:02 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
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
Windows 一键还原
http://www.yjhy.com
Floor 2 Posted 2006-12-11 03:16 ·  中国 河南 郑州 电信
中级用户
★★
Credits 439
Posts 170
Joined 2006-01-09 20:29
20-year member
UID 48707
Status Offline
如果 "#%drive%"=="#" 则跳转到sub_18h
如果 "#%filename%"=="#" 则跳转到sub_18h

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

set.ini?
_set.ini?
bat c c++
Floor 3 Posted 2006-12-11 03:20 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
It's quite messy ^_^, by the way, the obtained path is \aaa1\.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 4 Posted 2006-12-11 03:43 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Try the following code:
@echo off
Rem Read the settings file Set.ini
For /f "tokens=1,2* delims=:\" %%i In (c:\set.ini) Do (
If "%%k"=="" Goto sub_18h
echo %%i %%j %%k
)
pause&goto :eof
:sub_18h
cls
Echo.
Echo The custom path format is incorrect, please reset it .
Echo.
pause
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 5 Posted 2006-12-11 03:53 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
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.
Windows 一键还原
http://www.yjhy.com
Floor 6 Posted 2006-12-11 04:03 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
Originally posted by ccwan at 2006-12-11 03:43:
Try the following code:
@echo off
Rem Read the configuration file Set.ini
For /f "tokens=1,2* delims=:\" %%i In (c:\set.ini) Do (
If "%%k"=="" Goto sub_1 ...


There is a problem with this code, that is, an error message appears when there is no K value, but the format like E:\bbb2.gho should be allowed.
Windows 一键还原
http://www.yjhy.com
Floor 7 Posted 2006-12-11 05:36 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
When there is no drive letter in the path, your code will take the current drive letter. So, %drive% is never empty.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 8 Posted 2006-12-11 06:01 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
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.
Windows 一键还原
http://www.yjhy.com
Floor 9 Posted 2006-12-11 06:10 ·  中国 河南 郑州 电信
中级用户
★★
Credits 439
Posts 170
Joined 2006-01-09 20:29
20-year member
UID 48707
Status Offline
:
: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
bat c c++
Floor 10 Posted 2006-12-11 06:15 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
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 ]
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 11 Posted 2006-12-11 06:21 ·  中国 河南 郑州 电信
中级用户
★★
Credits 439
Posts 170
Joined 2006-01-09 20:29
20-year member
UID 48707
Status Offline
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 ]
bat c c++
Floor 12 Posted 2006-12-11 06:23 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
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
Windows 一键还原
http://www.yjhy.com
Floor 13 Posted 2006-12-11 06:29 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Then I don't understand. There's no problem with E:\aaa1\bbb2.gho here, but an error occurs when accessing E:\aaa1.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 14 Posted 2006-12-11 06:35 ·  中国 河南 郑州 电信
中级用户
★★
Credits 439
Posts 170
Joined 2006-01-09 20:29
20-year member
UID 48707
Status Offline
re ccwan
Yes, I didn't test this just now. This is an error.
bat c c++
Floor 15 Posted 2006-12-11 06:41 ·  中国 河南 郑州 电信
中级用户
★★
Credits 439
Posts 170
Joined 2006-01-09 20:29
20-year member
UID 48707
Status Offline
:
: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
bat c c++
Forum Jump: