Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looking for a reliable way to determine if a drive letter is in use
#3
(05-08-2023, 03:46 PM)hanness Wrote: I'm looking for a reliable way to determine if a drive letter is in use but I'm running into some difficulties.

Take the following small clip as an example:

A$ = "F:\"
If _DirExists(A$) Then
    Print A$; " Exists"
Else
    Print A$; "Does not exist"
End If

Normally, this works fine and indicates if the drive letter contained in A$ exists. But now consider these two exceptions:

1) Suppose I have a thumbdrive attached to the system that has been wiped clean. By wiped clean, I mean you open DISKPART, select the thumbdrive, and perform a "CLEAN" on that drive. In this instance, there will be no partitions on the drive, but in File Explorer, the drive still shows up with a drive letter. However, the clip above will indicate that this drive letter does NOT exist. As a result, if I try to assign that drive letter to another drive, it will fail because it is already in use.

2) The same thing happens if I connect a drive that has BitLocker encryption but has not yet been unlocked. The QB64PE code will indicate that the drive letter does not exist even though it is already in use.

Any suggestions on a better way to determine if a drive letter is in use?

Just off the top of my head perhaps:

A$ = "F:\."

The period added will force a root directory check maybe?
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply


Messages In This Thread
RE: Looking for a reliable way to determine if a drive letter is in use - by TerryRitchie - 05-08-2023, 03:53 PM



Users browsing this thread: 3 Guest(s)