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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check For Existance of Drive.

Status
Not open for further replies.

Ed2020

Programmer
Nov 12, 2001
1,899
GB
I want to check to see if a user of one of my system has an E:\ drive set up on their machine.

I thought I could do this with the Dir() function, but this doesn't seem to work.

Anybody got any ideas?

Ed Metcalfe.
 
One idea, using Dir(), could be to trap the failure to change to the E: drive (if it didn't exist) in an On Error Goto routine.
This isn't very elegant, however, so I'll post back when I've had a better idea.
 
I don't know whether you've tried it or not but try using the dir function with the vbdirectory attribute

dir("E:\",vbdirectory)

otherwise try using the filesystem object something like this.

Sub ShowDriveList
Dim fs, d, dc, s, n
Set fs = CreateObject("Scripting.FileSystemObject")
Set dc = fs.Drives
For Each d in dc
if d.driveletter = "E" then
found = true
end if
Next
MsgBox s
End Sub

Mark

The key to immortality is to make a big impression in this life!!
 
Got it - just use ChDrive. As in

ChDrive "E" ' Make "E" the current drive.

Again, it would need an error trapper.
I think Spellman (above) has the more elegant solution.
 
Thanks all. ChDrive works a treat.

Ed Metcalfe.e
 
I see this code in another site. I tried and it works perfectly.
It returns true or false and works with dir or file.


Function AsfFichDir(stPath As String, Optional lngType As Long) As Integer
'To check for a file - AsfFichDir("c:\winnt\win.ini")
'To check for a Dir - AsfFichDir("c:\msoffice",vbdirectory)

On Error Resume Next
AsfFichDir = Len(Dir(stPath, lngType)) > 0

End Function
 
Hi Ed!
Try my function mybe:

Function IsDriveReady(Optional DrvLetter As String = "A") As Boolean
'Function returns true if drive is ready
'and it stands to reason exists.
'Drive "A:" default drive

Dim fs, d, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set d = fs.GetDrive(DrvLetter)
IsDriveReady = d.IsReady
End Function


dim bln as boolean
bln=IsDriveReady 'Check for drive "A:" (default)

if not IsDriveReady("D") then
exit sub
end if


Aivars
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top