|
Answer» Sorry if this can be found elsewhere on the forum, but after a half dozen searches using VARIOUS phrases I couldn't find the answer.
What I need help with is how to find a specific "flag" file that resides in the root directory of a drive. It's probable that the drive letter will change which is why I need to be able to iterate through the list of drives on the machine.
Pseudo code would be:
Code: [Select]for each DRIVELETTER in E: - Z: if exists flag_file.txt set X = driveletter return end end
do something with X
Thanks for your help. Henry coding is base on your pseudocode:
Code: [Select]@echo off
for %%a in (e F g h i j k l m n o p q r s t u v w x y z) do ( if exist %%a:\flag_file.txt ( set x=%%a:\ goto:x ) ) if not defined x echo flag_file.txt Not Found & goto:EOF :x echo First Found Drive=%x% Quote from: Reno on March 21, 2009, 05:55:34 AM coding is base on your pseudocode:
Code: [Select]@echo off
for %%a in (e f g h i j k l m n o p q r s t u v w x y z) do ( if exist %%a:\flag_file.txt ( set x=%%a:\ goto:x ) ) if not defined x echo flag_file.txt Not Found & goto:eof :x echo First Found Drive=%x%
That's perfect! I knew that there had to be an "elegant" way of doing this, but finding good documentation on the use of the For command hasn't been easy.
Many thanks!!
- Henry
|