Page 1 of 1

Simple DriveExist procedure MULTI [Win -Mac - Linux]

Posted: Fri Dec 05, 2014 1:50 pm
by minimy
Hi this is a simple disc exist, return true or false.
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:\")

Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]

Posted: Fri Dec 05, 2014 2:23 pm
by Little John
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.

Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]

Posted: Sat Dec 06, 2014 5:07 am
by kenmo

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
Only tested on Windows though :)

Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]

Posted: Sat Dec 06, 2014 3:45 pm
by Tenaja
kenmo wrote:

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
Only tested on Windows though :)
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.

Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]

Posted: Sun Dec 07, 2014 2:03 am
by PB
> 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.

Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]

Posted: Mon Feb 02, 2015 5:07 pm
by minimy
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.
Hi PBmaniacs! ;-)..
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

Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]

Posted: Tue Feb 03, 2015 8:15 pm
by jassing
minimy wrote:
PB wrote:> If the drive letter is a mapped network drive, and you are not
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]

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
Since you don't actually care if there is more than one file -- you only need to test for the one entry & be done...

Re: Simple DriveExist procedure MULTI [Win -Mac - Linux]

Posted: Fri Feb 13, 2015 10:12 pm
by minimy
jassing wrote:
minimy wrote:
PB wrote:> If the drive letter is a mapped network drive, and you are not
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]

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
Since you don't actually care if there is more than one file -- you only need to test for the one entry & be done...
Thanks jassing, youre right, but i dont know another way.. the search continue friend! :wink: