![]() |
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-11-24 09:12 |
47,820 topics / 349,938 posts / today 0 new / 48,298 members |
| DOS批处理 & 脚本技术(批处理室) » Ask about batch processing: How to confirm whether a specified file exists on the hard disk? |
| Printable Version 6,359 / 26 |
| Floor16 lianjiang2004 | Posted 2006-10-30 06:52 |
| 金牌会员 Posts 1,884 Credits 3,946 | |
|
Tested on a virtual machine, would it be different on a real machine? Let's use a real DOS to see.
Report the test result, the result on the real machine is completely the same as that on the virtual machine. Using the virtual machine is mainly for convenient screenshotting. [ Last edited by lianjiang2004 on 2006-10-30 at 07:05 AM ] |
|
| Floor17 lxmxn | Posted 2006-10-30 07:15 |
| 版主 Posts 4,938 Credits 11,386 | |
|
It's not about you testing any virtual machine or DOS real mode. It's that the DOS system doesn't support the execution of symbols like "(" and ")" and "&", so you need to use statements like if and goto for workarounds.. |
|
| Floor18 lianjiang2004 | Posted 2006-10-30 07:29 |
| 金牌会员 Posts 1,884 Credits 3,946 | |
|
I only know a little bit about DOS, usually I just modify others' autoexec.bat and so on. Can you take a look at my problem? How to write it under DOS?
I'm sorry, I didn't make the problem clear at the beginning. [ Last edited by lianjiang2004 on 2006-10-30 at 07:33 AM ] |
|
| Floor19 fastslz | Posted 2006-10-30 07:45 |
| 铂金会员 Posts 2,315 Credits 5,493 From 上海 | |
|
First, it's important to state that the operating environment is very important~~
|
|
| Floor20 mountvol | Posted 2006-10-30 07:57 |
| 初级用户 Posts 117 Credits 186 | |
|
```
for %%i in (o n m l k j i h g f e d c) do if exist %%i:\aaa.txt set drive=%%i ``` |
|
| Floor21 lianjiang2004 | Posted 2006-10-30 07:58 |
| 金牌会员 Posts 1,884 Credits 3,946 | |
|
Used in DOS boot disks. Thank you.
|
|
| Floor22 hhl | Posted 2006-10-30 08:05 |
| 初级用户 Posts 14 Credits 35 | |
|
Moderator namejm, I have some doubts about the code you wrote above. It seems that it can only find the first partition containing aaa.txt. Is that correct?
|
|
| Floor23 fastslz | Posted 2006-10-30 08:08 |
| 铂金会员 Posts 2,315 Credits 5,493 From 上海 | |
|
@echo off
for %%a in (c d e f g h i j k l m n o) do if exist %%a:\aaa.txt set 输出盘符变量=%%a for %%b in (c d e f g h i j k l m n o) do if "%输出盘符变量%"=="%%b" echo aaa.txt位于 %%b: |
|
| Floor24 lianjiang2004 | Posted 2006-10-30 09:04 |
| 金牌会员 Posts 1,884 Credits 3,946 | |
|
### 这里可能原文本就是这样,按照要求直接呈现翻译后的内容(因为原内容主要是代码相关,这里就是保留原样呈现)
@echo off for %%a in (c d e f g h i j k l m n o) do if exist %%a:\aaa.txt set 输出盘符变量=%%a for %%b in (c d e f g h i j k l m n o) do if "%输出盘符变量%"=="%%b" ... Ask: The for %%a sentence has given the variable the drive letter where aaa.txt exists. What is the function of the for %%b sentence? Can it be omitted? |
|
| Floor25 fastslz | Posted 2006-10-30 09:23 |
| 铂金会员 Posts 2,315 Credits 5,493 From 上海 | |
|
Dizzy~ All the first sentences can be removed. ^_^
The second sentence: for is to meet your requirements (if it exists, output the drive letter to a variable and perform other tasks; otherwise, continue searching until drive O ends.) You can change echo aaa.txt located in %%b: to goto %%b: or edit %%b:\aaa.txt |
|
| Floor26 lianjiang2004 | Posted 2006-10-30 10:08 |
| 金牌会员 Posts 1,884 Credits 3,946 | |
|
Thanks, it seems I understand something.
Thanks to everyone's enthusiastic answers!!! |
|
| Floor27 namejm | Posted 2006-10-30 11:20 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
Originally posted by hhl at 2006-10-30 08:05: Completely correct. Because the original poster said that as long as it is found, it will display and perform other actions, so it was written like that. If you want to find all partitions containing aaa.txt, it is actually not difficult. |
|
| Prev 1 2 |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |