Source language: Translate to:

Find your CD in Unknown Drive

NeoBook tips, tricks, code samples and more...

Moderator: Neosoft Support

Find your CD in Unknown Drive

Postby Jim Brammer » Mon May 06, 2002 9:24 pm

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

...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.
Jim Brammer

Find your CD in Unknown Drive

Postby aaronsiler » Thu Dec 18, 2003 10:15 am

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

Find your CD in Unknown Drive

Postby Sam Cox » Thu Dec 18, 2003 10:24 am

Hi Aaron,

Welcome to the Forum.

Yes, the forum software has a problem with brackets.  This post by gk51 ... ... 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)
User avatar
Sam Cox
Posts: 768
Joined: Fri Apr 01, 2005 7:30 am
Location: Loveland CO USA

Return to NeoBook Knowledgebase

Who is online

Users browsing this forum: No registered users and 0 guests