List all available volumes

Just starting out? Need help? Post your questions and find answers here.
User avatar
viiartz
User
User
Posts: 70
Joined: Tue Mar 28, 2006 2:00 am

List all available volumes

Post by viiartz »

Hi all,

I've been searching the forum for how to list all available volumes (drives) and how to set a environment variable.

the idea is to code a console app to find a volume label and assign that volume drive letter to a environment variable to be used in a batch file.

any hits...

thanks in advance :D
Thanks,
ViiArtz
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: List all available volumes

Post by srod »

Based upon some code taken from PureArea :

Code: Select all

Structure DriveInfo
  DriveLetter$
  Volume$
EndStructure


Procedure GetAllDrives(List Drive.DriveInfo())
  Protected memLen, *buffer, numDrives, *ptrChar.CHARACTER, i
  memLen = GetLogicalDriveStrings_(0, 0)
  If memlen
    *buffer = AllocateMemory(memLen * SizeOf(CHARACTER))
    If *buffer
      numDrives = GetLogicalDriveStrings_(memLen,*buffer)>>2
      *ptrChar = *buffer
      For i = 1 To numDrives
        AddElement(Drive())
        Drive()\DriveLetter$ = UCase(PeekS(*ptrChar,3))
        *ptrChar + SizeOf(CHARACTER)<<2
        Drive()\Volume$ = Space(256)
        GetVolumeInformation_(Drive()\DriveLetter$, @Drive()\Volume$,255,0,0,0,0,0)
      Next
      FreeMemory(*buffer)    
    EndIf
  EndIf
EndProcedure 

;Test.
  NewList Drive.DriveInfo()
  GetAllDrives(Drive())
  ;Take a look at the results.

  ForEach Drive()
    Debug Drive()\DriveLetter$  + " " + Drive()\Volume$
  Next
I may look like a mule, but I'm not a complete ass.
Post Reply