Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check if file exists on a cd? NOT the same as on the HD

Status
Not open for further replies.

HotMadras

Programmer
Apr 20, 2001
74
GB
I need to check if a file exists in order to make sure that a user has put a disc in their cd-rom drive. At the moment it seems I need to use an error trap to stop the program exiting with a run-time error (using the 'dir(filename)<>&quot;&quot;' method) in the case that the user doesn't have the cd in the drive. This isn't satisfactory because I need to be able to take account of the possibility of multiple drives (the cd might be in drive e or f for example, just because the program doesn't find it in the first drive it checks, doesn't mean it should assume it isn't there).

I can't seem to find a simple way of saying &quot;if there is a cd in any drive that has this file on it continue, if not give an error and exit cleanly&quot;. If anyone knows a good way of doing this, I'd be much obliged.
 
Here's a suggestion: look at the Drives collection of the FileSystemObject and the Drive object. You could loop through the Drives colletion and check the type of each drive. For example, something like the following might work:
Code:
Dim FS as New FileSystemObject
Dim d as Drive

For Each d in FS.Drives
   If d.DriveType = 4 Then   'the drive is a CD-ROM
      'Do your file checking
   end if
Next
Note that you'll need a reference to the MS Scripting runtime to use these.
 
In 'days of yore', this would (probably) be useful. In these times (of larger discs), you MAY find some users who copy their CD's to 'folders' - and expect to ba able to point their apps to the &quot;new&quot; location.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top