![]() |
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-09-15 13:15 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » How to determine whether a parameter is a file or a directory |
| Printable Version 3,034 / 5 |
| Floor1 wentimao | Posted 2006-06-03 20:17 |
| 初级用户 Posts 27 Credits 110 | |
|
In batch processing, when operating on a file passed in as an argument, if the file doesn't exist but the directory does, an error will occur during operation. So I want to make a judgment. My operation is to use if exist path\nul, but when there are long file names, it can't be judged. How should I do it? How to judge whether a parameter passed to the batch is a file name or a directory name?
|
|
| Floor2 willsort | Posted 2006-06-03 20:25 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
关于wentimao的回复:
提问时请注明你的系统环境(DOS/98/XP)和脚本环境(COMMAND/CMD),如果将这些参数写在你的用户签名中,就无需每次都转发这些数据。 在CMD中判断文件或目录是否存在,一般不再使用NUl了。 判断是否存在目录:if exist "%~f1\" ... 判断是否存在文件:if exist "%~f1" if not exist "%~f1\"... The reply to wentimao: Please indicate your system environment (DOS/98/XP) and script environment (COMMAND/CMD) when asking a question. If you write these parameters in your user signature, you don't need to repost these data every time. In CMD, to judge the existence of a file or directory, NUl is generally not used anymore. To judge whether a directory exists: if exist "%~f1\" ... To judge whether a file exists: if exist "%~f1" if not exist "%~f1\"... |
|
| Floor3 willsort | Posted 2006-06-06 19:23 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re wentimao:
Regarding the existence judgment issue of the same-named directory and file you mentioned in other topics, the reply is as follows: 1. In CMD and COMMAND, it is very rare to have the situation where the directory and file have the same name and path. This is not allowed by the file system rules of DOS/Windows; if it really occurs, it should be a problem of the system, and it should be solved by the system itself, not by our code to be compatible with this problem. 2. If you really want to judge "whether the file with the same name exists when the directory exists", you can use (but it is not recommended) the following code: (for /f "usebackq" in ("%~f1") do ...)2>nul |
|
| Floor4 sohu | Posted 2010-12-04 15:58 |
| 新手上路 Posts 13 Credits 14 | |
|
I want to ask: How to know whether your script environment is COMMAND or CMD?
|
|
| Floor5 Hanyeguxing | Posted 2010-12-04 16:28 |
| 银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂 | |
|
Under what system does it run? Is it run directly in cmd or in a batch file?
|
|
| Floor6 sohu | Posted 2010-12-04 17:06 |
| 新手上路 Posts 13 Credits 14 | |
Originally posted by Hanyeguxing at 2010-12-4 16:28: Thank you very much for your reply, I thought these posts were several years old. Hehe Finally saw someone online Handshake... |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |