Page 1 of 1

Find your CD in Unknown Drive

PostPosted: Mon May 06, 2002 9:24 pm
by Jim Brammer
The problem is your EXE is on the users hard drive but needs to access files located on a CD. More & more systems have more than one CD drive these days. (CD, DVD, CDRW)   Not knowing which CD drive the user placed your CD into makes it difficult to code for. But, the solution (in this case) is fairly simple.  It is your CD so, you know what files are on the CD. All you need to do is look for a particular file on the CD within a loop....



SetVar "[DriveString]" "D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
StrParse "[DriveString]" "," "[Drive]" "[DriveCount]"
Loop "1" "[DriveCount]" "[X]"
FileExists "[Drive[x]]:\MyFolder\MyFile.ext" "[FileFound]"
If "[FileFound]" "=" "True"
SetVar "[x]" "[DriveCount]+1"
.... do whatever you need to here - you've found the CD
EndIf
EndLoop



...or something to that effect. The string [DriveString] contains all the letters of drives from D to Z. That string is parsed and the drive letters stored in the array [Drive].  The Loop cycles through each drive letter looking for the specified file on each different drive. When found, it breaks out of the loop to perform other actions.

Find your CD in Unknown Drive

PostPosted: Thu Dec 18, 2003 10:15 am
by aaronsiler
I found though that I had to add an extra bracket at the end when referring to the Array.  (i.e.: [Drive[x] ] - with no space between the brackets)

I think that you had it that way originally, but this forum site removed double brackets.

Thanks!  This script really helped me out.

- Aaron Siler
silerconsulting.com

Find your CD in Unknown Drive

PostPosted: Thu Dec 18, 2003 10:24 am
by Sam Cox
Hi Aaron,

Welcome to the Forum.

Yes, the forum software has a problem with brackets.  This post by gk51 ...

http://www.neosoftware.com/cgi-bin/ikon ... 0&topic=13

explains the problem and the work-arounds.

Cutting and pasting code with adjacent brackets from NeoBook into this forum doesn't work like you would expect, and everyone reading code snippets posted on this forum should take care to count brackets to make sure that the number of opening brackets matches the number of closing brackets.

(Edited by Sam Cox at 5:25 am on Dec. 18, 2003)