Author Topic: Windows drives  (Read 3604 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Windows drives
« on: February 13, 2021, 02:47:29 am »
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.  
  3.     FUNCTION GetLogicalDrives&
  4.     'drives that exist are stored in bit position from 0 to 31.   Bit 0 = Drive A, Bit 1 = Drive B, Bit 2 = Drive C, ect
  5.     FUNCTION GetLogicalDriveStringsA& (BYVAL nBufferLength AS LONG, lpBuffer AS STRING)
  6.     FUNCTION GetDriveTypeA& (nDrive AS STRING)
  7.  
  8. 'Drive types will be one of the following:
  9. CONST DRIVE_UNKNOWN = 0
  10. CONST DRIVE_ABSENT = 1
  11. CONST DRIVE_REMOVABLE = 2
  12. CONST DRIVE_FIXED = 3
  13. CONST DRIVE_REMOTE = 4
  14. CONST DRIVE_CDROM = 5
  15. CONST DRIVE_RAMDISK = 6
  16.  
  17.  
  18. PRINT "Drives detected:"
  19.  
  20. FOR i = 0 TO 25 'get all the drives as a bit value array
  21.     IF _READBIT(GetLogicalDrives, i) THEN PRINT CHR$(65 + i)
  22.  
  23. 'Get all the drives in a string
  24. strSave$ = STRING$(255, 0)
  25. ret& = GetLogicalDriveStringsA(255, strSave$)
  26. PRINT strSave$
  27.  
  28. 'Get the drive type for drive C:\ as an example
  29. GDT = GetDriveTypeA("C:\")
  30.     CASE 2
  31.         PRINT "Removable"
  32.     CASE 3
  33.         PRINT "Drive Fixed"
  34.     CASE 4
  35.         PRINT "Remote"
  36.     CASE 5
  37.         PRINT "Cd-Rom"
  38.     CASE 6
  39.         PRINT "Ram disk"
  40.     CASE ELSE
  41.         PRINT "Unrecognized"
  42.  
  43.  
  44.  

Get a list of the available drives on your machine, and some info on what type they are.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Windows drives
« Reply #1 on: February 13, 2021, 10:16:23 am »
Oh yeah I did this same thing with a post a while back when that one guy asked about seeing how much space is left on a drive
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Windows drives
« Reply #2 on: February 13, 2021, 10:32:41 am »
Oh that looks like it would be handy, I'll be watching for feedback from testers.

Looks good on my system. Didn't even know I had a D: drive or name of my CD drive. Tried SD card and detected as G and removable.

D: drive is that mine or Windows?

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Windows drives
« Reply #3 on: February 13, 2021, 10:48:36 am »
It works for me.  Nice to see _READBIT used too - another keyword I need to get to know.

Someone put my version up in the wiki a few years ago, but yours is more complete and should replace it.

- Dav

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Windows drives
« Reply #4 on: February 13, 2021, 10:51:35 am »
Yeah, this is what I did a few months back for Richard.

Code: QB64: [Select]
  1.  
  2. CONST DRIVE_UNKNOWN = 0
  3. CONST DRIVE_NO_ROOT_DIR = 1
  4. CONST DRIVE_REMOVABLE = 2
  5. CONST DRIVE_FIXED = 3
  6. CONST DRIVE_REMOTE = 4
  7. CONST DRIVE_CDROM = 5
  8. CONST DRIVE_RAMDISK = 6
  9.  
  10.     FUNCTION GetDiskFreeSpace% ALIAS GetDiskFreeSpaceExA (lpDirectoryName AS STRING, BYVAL lpFreeBytesAvailableToCaller AS _OFFSET, BYVAL lpTotalNumberOfBytes AS _OFFSET, BYVAL lpTotalNumberOfFreeBytes AS _OFFSET)
  11.     FUNCTION GetDriveType~& ALIAS GetDriveTypeA (lpRootPathName AS STRING)
  12.  
  13. DIM totalFreeBytesOnDisk AS _UNSIGNED _INTEGER64
  14.  
  15. IF GetDiskFreeSpace("L:\", 0, 0, _OFFSET(totalFreeBytesOnDisk)) THEN
  16.     SELECT CASE totalFreeBytesOnDisk
  17.         CASE IS < 1024
  18.             PRINT USING "    ####, B Available"; totalFreeBytesOnDisk,
  19.         CASE IS < (1024 ^ 2) AND totalFreeBytesOnDisk >= 1024
  20.             PRINT USING "####,.## KB Available"; (totalFreeBytesOnDisk / 1024)
  21.         CASE IS < (1024 ^ 3) AND totalFreeBytesOnDisk >= (1024 ^ 2)
  22.             PRINT USING "####,.## MB Available"; (totalFreeBytesOnDisk / (1024 ^ 2))
  23.         CASE IS < (1024 ^ 4) AND totalFreeBytesOnDisk >= (1024 ^ 3)
  24.             PRINT USING "####,.## GB Available"; (totalFreeBytesOnDisk / (1024 ^ 3))
  25.         CASE IS < (1024 ^ 5) AND totalFreeBytesOnDisk >= (1024 ^ 4)
  26.             PRINT USING "####,.## TB Available"; (totalFreeBytesOnDisk / (1024 ^ 4))
  27.     END SELECT
  28.  
  29. SELECT CASE GetDriveType("L:\")
  30.     CASE DRIVE_UNKNOWN
  31.         PRINT "Unkown drive type"
  32.     CASE DRIVE_NO_ROOT_DIR
  33.         PRINT "Invalid path"
  34.     CASE DRIVE_REMOVABLE
  35.         PRINT "Removable media"
  36.     CASE DRIVE_FIXED
  37.         PRINT "Fixed media"
  38.     CASE DRIVE_REMOTE
  39.         PRINT "Network media"
  40.     CASE DRIVE_CDROM
  41.         PRINT "CD-ROM drive"
  42.     CASE DRIVE_RAMDISK
  43.         PRINT "RAM disk"
I guess I didn't get the drive letter on this one but I made it so you could input the drive letter and get the info for it
« Last Edit: February 13, 2021, 10:53:39 am by SpriggsySpriggs »
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Windows drives
« Reply #5 on: February 13, 2021, 11:04:36 am »
What is "No Root Dir", something linked to Internet or cloud?

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Windows drives
« Reply #6 on: February 13, 2021, 11:33:46 am »
Not sure. I'd have to read the MSDN again
Shuwatch!

Offline euklides

  • Forum Regular
  • Posts: 128
    • View Profile
Re: Windows drives
« Reply #7 on: February 14, 2021, 11:24:17 am »
Well, well, well.
Not really true...
So an usb hard drive  (an also an usb3 ssd external drive) is detected as ""Fixed media"...
The very good answer is "Removal hard disk".

I have the solution of this in Visual Basic Excel, but not in QB64 !!!
Why not yes ?