|
lianjiang2004
金牌会员
     
积分 3946
发帖 1884
注册 2006-1-20
状态 离线
|
『楼 主』:
请教:如何判断输入的变量为空的。
使用 LLM 解释/回答一下
请教:如何判断输入的变量为空的。
目的:
根据set.ini里的内容如 E:\aaa1\bbb2.gho,即包括盘符,目录,文件名,其中目录可无。
通过分离set.ini里的字符,分别获得盘符,目录,文件名的变量。
假如无盘符或无文件名,需重新设定,否则继续。
下面是我的代码,请教哪里出错了?谢谢。
------------------
:sub_18d
Rem 读取设置文件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 自定义路径格式不正确,需重新设置[正确格式如 E:\aaa1\bbb2.gho]。
Echo.
pause
Goto Set
:sub_18e
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 .
Echo.
pause
Goto Set
:sub_18e
|

Windows 一键还原
http://www.yjhy.com |
|
2006-12-11 03:02 |
|
|
a9319751
中级用户
  
积分 439
发帖 170
注册 2006-1-9
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
If "#%drive%"=="#" Goto sub_18h
If "#%filename%"=="#" Goto sub_18h
Rem 读取设置文件Set.ini
For /f "tokens=*" %%i In (c:\_set.ini) Do (
set.ini?
_set.ini?
如果 "#%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++ |
|
2006-12-11 03:16 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
是挺乱的^_^,顺便说一下,获得的路径是\aaa1\.
It's quite messy ^_^, by the way, the obtained path is \aaa1\.
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-11 03:20 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
试一下下面的代码:
@echo off
Rem 读取设置文件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 自定义路径格式不正确,需重新设置。
Echo.
pause
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
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-11 03:43 |
|
|
lianjiang2004
金牌会员
     
积分 3946
发帖 1884
注册 2006-1-20
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Originally posted by a9319751 at 2006-12-11 03:16:
If "#%drive%"=="#" Goto sub_18h
If "#%filename%"=="#" Goto sub_18h
Rem 读取设置文件Set.ini
For /f "tokens=*" %%i In (c:\_s ...
不好意思,是_set.ini。
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 |
|
2006-12-11 03:53 |
|
|
lianjiang2004
金牌会员
     
积分 3946
发帖 1884
注册 2006-1-20
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by ccwan at 2006-12-11 03:43:
试一下下面的代码:
@echo off
Rem 读取设置文件Set.ini
For /f "tokens=1,2* delims=:\" %%i In (c:\set.ini) Do (
If "%%k"=="" Goto sub_1 ...
这段代码有些问题,就是没有K值时出现错误提示,但是E:\bbb2.gho这种格式是该允许的。
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 |
|
2006-12-11 04:03 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
当路径中没有盘符时,你的代码会取当前盘符。所以, %drive%永不为空。
When there is no drive letter in the path, your code will take the current drive letter. So, %drive% is never empty.
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-11 05:36 |
|
|
lianjiang2004
金牌会员
     
积分 3946
发帖 1884
注册 2006-1-20
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by ccwan at 2006-12-11 05:36:
当路径中没有盘符时,你的代码会取当前盘符。所以, %drive%永不为空。
问题是目录为空也不行了。比如e:\sys.gho,实际上就是保存到根目录。我要这也可以。
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 |
|
2006-12-11 06:01 |
|
|
a9319751
中级用户
  
积分 439
发帖 170
注册 2006-1-9
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
:sub_18d
Rem 读取设置文件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 自定义路径格式不正确,需重新设置[正确格式如 E:\aaa1\bbb2.gho]。
Echo.
pause
Goto Set
:sub_18e
pause
:
: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 .
Echo.
pause
Goto Set
:sub_18e
pause
|

bat c c++ |
|
2006-12-11 06:10 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
re a9319751:
""是一处,但你试一下就知道,没有*.gho时,directory=\ 还是不行。
Last edited by ccwan on 2006-12-11 at 06:17 AM ]
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 ]
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-11 06:15 |
|
|
a9319751
中级用户
  
积分 439
发帖 170
注册 2006-1-9
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
re ccwan
我试了
e:\sys.gho
e:\sys\sys.gho
e:\
都可以啊
Last edited by a9319751 on 2006-12-11 at 06:24 AM ]
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++ |
|
2006-12-11 06:21 |
|
|
lianjiang2004
金牌会员
     
积分 3946
发帖 1884
注册 2006-1-20
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
根据2楼的改了,好像可以。
-----------
:sub_18d
Rem 读取设置文件_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 自定义路径格式不正确,需重新设置[正确格式如 E:\aaa1\bbb2.gho]。
Echo.
pause
Goto Set_0
:sub_18e
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 .
Echo.
pause
Goto Set_0
:sub_18e
|

Windows 一键还原
http://www.yjhy.com |
|
2006-12-11 06:23 |
|
|
ccwan
金牌会员
     
积分 2725
发帖 1160
注册 2006-9-23 来自 河北廊坊
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
那我可不明白了,我这里E:\aaa1\bbb2.gho没事,
E:\aaa1时出错
Then I don't understand. There's no problem with E:\aaa1\bbb2.gho here, but an error occurs when accessing E:\aaa1.
|

三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。 |
|
2006-12-11 06:29 |
|
|
a9319751
中级用户
  
积分 439
发帖 170
注册 2006-1-9
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
re ccwan
是的,刚才我没测试这个
这个是个错误
re ccwan
Yes, I didn't test this just now. This is an error.
|

bat c c++ |
|
2006-12-11 06:35 |
|
|
a9319751
中级用户
  
积分 439
发帖 170
注册 2006-1-9
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
:sub_18d
Rem 读取设置文件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 自定义路径格式不正确,需重新设置[正确格式如 E:\aaa1\bbb2.gho]。
Echo.
pause
Goto Set
:sub_18e
Echo 自定义
pause
加了一句
:
: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 .
Echo.
pause
Goto Set
:sub_18e
Echo Custom
pause
Added a sentence
|

bat c c++ |
|
2006-12-11 06:41 |
|