Procedure DriveExist(Drive.s)
Protected exist
If CreateFile(0,drive+"test")
exist=#True : CloseFile(0) : DeleteFile(drive+"test")
Else
exist=#False
EndIf
ProcedureReturn exist
EndProcedure
Debug DriveExist("c:\")
Debug DriveExist("J:\")
Simple DriveExist procedure MULTI [Win -Mac - Linux]
Simple DriveExist procedure MULTI [Win -Mac - Linux]
Hi this is a simple disc exist, return true or false.
If translation=Error: reply="Sorry, Im Spanish": Endif
-
- Addict
- Posts: 4770
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]
If the regarding disc is write-protected, your above procedure will retuen #False, even though the disc does exist.
Here is a solution which is better IMHO.
Here is a solution which is better IMHO.
Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]
Code: Select all
Macro PathExists(Path)
Bool(FileSize(Path) = -2)
EndMacro
For i = 'A' To 'Z'
If (PathExists(Chr(i) + ":\"))
Debug Chr(i) + ":\ exists"
EndIf
Next i

Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]
This works nicely, except for one thing. If the drive letter is a mapped network drive, and you are not connected to the required network, you still get #True.kenmo wrote:Only tested on Windows thoughCode: Select all
Macro PathExists(Path) Bool(FileSize(Path) = -2) EndMacro For i = 'A' To 'Z' If (PathExists(Chr(i) + ":\")) Debug Chr(i) + ":\ exists" EndIf Next i
Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]
> If the drive letter is a mapped network drive, and you are not
> connected to the required network, you still get #True
Same if there's no media in a DVD drive: it returns #True, even
though there's nothing there to access at all.
> connected to the required network, you still get #True
Same if there's no media in a DVD drive: it returns #True, even
though there's nothing there to access at all.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]
Hi PBmaniacs!PB wrote:> If the drive letter is a mapped network drive, and you are not
> connected to the required network, you still get #True
Same if there's no media in a DVD drive: it returns #True, even
though there's nothing there to access at all.

I write a little piece of code to detect if one drive is ready to use.
Code: Select all
Procedure DiscReady(disco.s)
Protected files.l=0,exist.b=#False
If ExamineDirectory(0,disco+":\","*.*")
While NextDirectoryEntry(0)
files+1
Wend
FinishDirectory(0)
If files>0:exist=#True:EndIf
EndIf
ProcedureReturn exist
EndProcedure
Debug DiscReady("c"); HD
Debug DiscReady("d"); CDROM
If translation=Error: reply="Sorry, Im Spanish": Endif
Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]
While your code works, if it contains lots of files (thousands) it (potentially) will cause a long delay (especially on slow media) You may want to consider something like: [aircode=on]minimy wrote:PB wrote:> If the drive letter is a mapped network drive, and you are not
Code: Select all
Procedure DiscReady(disco.s)
Protected hDir, exist.b=#False
hDir = ExamineDirectory(#PB_ANY,disco+":\","*.*")
If hDir
If NextDirectoryEntry(hDir)
exist=#True
EndIf
FinishDirectory(hDir)
EndIf
ProcedureReturn exist
EndProcedure
Debug DiscReady("c"); HD
Debug DiscReady("d"); CDROM
Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]
Thanks jassing, youre right, but i dont know another way.. the search continue friend!jassing wrote:While your code works, if it contains lots of files (thousands) it (potentially) will cause a long delay (especially on slow media) You may want to consider something like: [aircode=on]minimy wrote:PB wrote:> If the drive letter is a mapped network drive, and you are notSince you don't actually care if there is more than one file -- you only need to test for the one entry & be done...Code: Select all
Procedure DiscReady(disco.s) Protected hDir, exist.b=#False hDir = ExamineDirectory(#PB_ANY,disco+":\","*.*") If hDir If NextDirectoryEntry(hDir) exist=#True EndIf FinishDirectory(hDir) EndIf ProcedureReturn exist EndProcedure Debug DiscReady("c"); HD Debug DiscReady("d"); CDROM

If translation=Error: reply="Sorry, Im Spanish": Endif