Searching for Drives
Searching for Drives
There are a large number of card readers that allow Compact Flash, SD, MMC etc cards to appear as standard disk drives. For example, my DANE-ELEC USB2 plugs into the USB port and offers four drives, F:,G:,H: and I:
The program I am involved with needs to scan all possible drives from C: to N: and then check to see if a specific file (DATA_LOG.BIN) exists on it.
Using GFA Basic I managed to check for drives by attempting to open the file <Drive$+":\NUL"> and using TRY ... CATCH to detect errors due to non existant drives. Then I used IF EXIST(drive$+"\DATA.BIN") to confirm the file existed. This worked Ok and no system messages ever appeared.
Using Pure BASIC, has anyone managed to perform a scan for drives without any system error messages appearing?
Having found the drive I intend checking for the file (always in root) by examining the return from ReadFile()
The program I am involved with needs to scan all possible drives from C: to N: and then check to see if a specific file (DATA_LOG.BIN) exists on it.
Using GFA Basic I managed to check for drives by attempting to open the file <Drive$+":\NUL"> and using TRY ... CATCH to detect errors due to non existant drives. Then I used IF EXIST(drive$+"\DATA.BIN") to confirm the file existed. This worked Ok and no system messages ever appeared.
Using Pure BASIC, has anyone managed to perform a scan for drives without any system error messages appearing?
Having found the drive I intend checking for the file (always in root) by examining the return from ReadFile()
Try this to get available drives (uses WIN API so it's not crossplatform):
Also for checking if a file exist, see documention on the 'FileSize()' command.
Code: Select all
Dim DriveString.s(30)
*buffer = AllocateMemory(256)
If *buffer = 0
; unable to allocate memory
End
EndIf
If GetLogicalDriveStrings_(254, *buffer)
pos.l = *buffer
index = 0
Repeat
DriveString(index) = PeekS(pos)
If DriveString(index) = ""
Break
Else
pos + Len(DriveString(index)) + 1
EndIf
index+1
ForEver
For i = 0 To index-1
Debug DriveString(i)
Next
Else
; Call failed, need some error handling
End
EndIf
FreeMemory(*buffer)
Thanks for the suggestion. I added a file size check using FileSize(), but I get a "No disk in the drive......" message requester from the system for the floppy drive and the empty card slots in the card reader.
What is needed is a test that the drive has a valid media... followed by a test for the media having the file.
Code: Select all
Dim DriveString.s(30)
*buffer = AllocateMemory(256)
If *buffer = 0
; unable to allocate memory
End
EndIf
If GetLogicalDriveStrings_(254, *buffer)
pos.l = *buffer
Index = 0
Repeat
DriveString(Index) = PeekS(pos)
If DriveString(Index) = ""
Break
Else
pos + Len(DriveString(Index)) + 1
EndIf
Index+1
ForEver
For i = 0 To Index-1
If FileSize(DriveString(i)+"DATA_LOG.BIN")<>-1
Debug "Found on drive:"+DriveString(i)
Else
Debug "Not on drive : "+DriveString(i)
EndIf
Next
Else
; Call failed, need some error handling
End
EndIf
-
GreenGiant
- Enthusiast

- Posts: 252
- Joined: Fri Feb 20, 2004 5:43 pm
Recognises it for me.
Code: Select all
SetErrorMode_(uMode)-
GreenGiant
- Enthusiast

- Posts: 252
- Joined: Fri Feb 20, 2004 5:43 pm
OK, I getting there! The following code works... I'm not sure that it is good code, but until tomorrow I'm happy to have something that works.
No system messages popping up despite several drives being empty... and the floppy rattles.
Ten hours at the keyboard! I'm off to open a bottle (maybe two) and cook a nice piece of salmon.
Good night all... 
No system messages popping up despite several drives being empty... and the floppy rattles.
Ten hours at the keyboard! I'm off to open a bottle (maybe two) and cook a nice piece of salmon.
Code: Select all
Dim DriveString.s(30)
*buffer = AllocateMemory(256)
If *buffer = 0
; unable to allocate memory
End
EndIf
If GetLogicalDriveStrings_(254, *buffer)
pos.l = *buffer
Index = 0
Repeat
DriveString(Index) = PeekS(pos)
If DriveString(Index) = ""
Break
Else
pos + Len(DriveString(Index)) + 1
EndIf
Index+1
ForEver
k2$="Not found"
;SEM_FAILCRITICALERRORS = 00001h
OldErrorMode.l = SetErrorMode_(1)
For i = 0 To Index-1
k$=DriveString(i)+"DATA_LOG.BIN"
If GetFileAttributes_(@k$)=-1
Junk.l=GetLastError_()
SetLastError_(0)
Else
k2$="Gotit"
EndIf
Next i
SetErrorMode_(OldErrorMode.l)
Debug k2$
Else
; Call failed, need some error handling
End
EndIf
