This code uses / misuses chdir to poll
for a drive while looping through
the alphabet A to Z.
Only for an OS that utilizes drive letters.
On a side note for nix systems a possible
solution would be to shell and use one of these
methods output the result to a text file and
then parse with freebasic.
https://linoxide.com/list-mounted-drives-on-linux/
edit 28/10/2021
Tweaked the code a bit using command(0) to set
the apppath was not such a hot idea.
As some reply's indicate there are many ways to Rome ;)
A shell approach for windows could be:
> fsutil fsinfo drives
and parse the output with freebasic
More info:
http://www.cryer.co.uk/brian/windows/ba ... etters.htm
Oh and one more thing it seems that chdir
does not recognize CD drives or the virtual kind
unless it contains a disc or is mounted with an iso
so that might be a thing to keep in mind.
Code: Select all
' scan for drive letters
' 2021 by thrive4
dim apppath as string = curdir
' setup drive scan
dim i as integer = 1
dim drivescan as integer = 65
dim drivenum as integer = 1
dim driveletter(1 to 26) as string
dim dummy as string
' scan for driveletters ascii 65 to 90 aka A to Z
do while drivescan < 91
dummy = chr(drivescan)
IF chdir(dummy + ":\") = 0 then
driveletter(drivenum) = dummy
drivenum += 1
end if
drivescan += 1
loop
' show driveletters found
do while i < drivenum
print "found " + driveletter(i) + ":\"
i += 1
loop
i = 1
drivenum = 1
' restore to application path
chdir(apppath)
sleep 5000
end