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-25 08:25
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask about batch processing: How to confirm whether a specified file exists on the hard disk? View 5,394 Replies 26
Floor 16 Posted 2006-10-30 06:52 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
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 ]
Floor 17 Posted 2006-10-30 07:15 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

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..
Floor 18 Posted 2006-10-30 07:29 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
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 ]
Floor 19 Posted 2006-10-30 07:45 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
First, it's important to state that the operating environment is very important~~
第一高手 第二高手

Floor 20 Posted 2006-10-30 07:57 ·  中国 湖北 荆门 电信
初级用户
★★
Credits 186
Posts 117
Joined 2006-08-14 14:50
19-year member
UID 60491
Status Offline
```
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
```
Floor 21 Posted 2006-10-30 07:58 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
Used in DOS boot disks. Thank you.
Floor 22 Posted 2006-10-30 08:05 ·  中国 上海 普陀区 电信
初级用户
Credits 35
Posts 14
Joined 2006-10-16 05:53
19-year member
UID 65933
Status Offline
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?
Floor 23 Posted 2006-10-30 08:08 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
@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:
第一高手 第二高手

Floor 24 Posted 2006-10-30 09:04 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
### 这里可能原文本就是这样,按照要求直接呈现翻译后的内容(因为原内容主要是代码相关,这里就是保留原样呈现)
@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?
Floor 25 Posted 2006-10-30 09:23 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
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
第一高手 第二高手

Floor 26 Posted 2006-10-30 10:08 ·  中国 安徽 马鞍山 电信
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
Thanks, it seems I understand something.
Thanks to everyone's enthusiastic answers!!!
Floor 27 Posted 2006-10-30 11:20 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Originally posted by hhl at 2006-10-30 08:05:
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 right?

  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.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Forum Jump: