List Computer Drives and Volume Informations
- DarkRookie
- User
- Posts: 20
- Joined: Wed Nov 24, 2010 5:47 pm
List Computer Drives and Volume Informations
I saw code to do this On purearea but it all is windows specific.
Is there a way to do it in linux and be demo friendly?
Is there a way to do it in linux and be demo friendly?
It is better to have a dumb question than a wrong answer!
Re: List Computer Drives and Volume Informations
look under /proc directory for the files partitions and mounts
Code: Select all
fn = ReadFile(#PB_Any,"/proc/partitions")
If fn
While Not Eof(fn)
Debug ReadString(fn)
Wend
EndIf
If fn
CloseFile(fn)
EndIf
Windows 11, Manjaro, Raspberry Pi OS


Re: List Computer Drives and Volume Informations
An alternative is to utilize the console command "df" and display volume
name, file system type, total space, free space, percentage used and
mount point (the space is displayed in "human readable" format using
the switch "-h", i.e. KB, MB, GB - whatever seems appropriate; if you
prefer to get all space values in the same notation, change "-h" against
"-B K" for KB, "-B M" for MB or "-B G" for GB):
name, file system type, total space, free space, percentage used and
mount point (the space is displayed in "human readable" format using
the switch "-h", i.e. KB, MB, GB - whatever seems appropriate; if you
prefer to get all space values in the same notation, change "-h" against
"-B K" for KB, "-B M" for MB or "-B G" for GB):
Code: Select all
ProgramID = RunProgram("df", "-h -T", "", #PB_Program_Open | #PB_Program_Read)
If ProgramID
While ProgramRunning(ProgramID)
If AvailableProgramOutput(ProgramID)
Output$ + ReadProgramString(ProgramID) + #CR$
EndIf
Wend
CloseProgram(ProgramID)
Debug Output$
EndIf
Re: List Computer Drives and Volume Informations
This is exactly what I need, the Windows specific code. I have not found it on purearea. Please, can you tell me where it is? Somewhere on http://www.purearea.net .....List Computer Drives and Volume Informations
DarkRookie wrote: I saw code to do this On purearea but it all is windows specific.
Thanks.
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: List Computer Drives and Volume Informations
Here some routines from my old project:charvista wrote:This is exactly what I need, the Windows specific code. I have not found it on purearea. Please, can you tell me where it is? Somewhere on http://www.purearea.net .....List Computer Drives and Volume Informations
DarkRookie wrote: I saw code to do this On purearea but it all is windows specific.
Thanks.
Code: Select all
EnableExplicit
Structure DriveInfos
DriveLetter.s
DriveType.l
NameOfVolume.s
EndStructure
Global NewList Drives.DriveInfos()
Procedure CountDrives()
Protected AllDriveNames.s, Size, i, *pAllDriveNames
Size = GetLogicalDriveStrings_(0, @AllDriveNames)
AllDriveNames = Space(Size)
Size = GetLogicalDriveStrings_(Size, @AllDriveNames)
ProcedureReturn Size / 4
EndProcedure
Procedure SearchDrives()
Protected AllDriveNames.s, Size, Count, i, *pAllDriveNames
ClearList(Drives())
Size = GetLogicalDriveStrings_(0, @AllDriveNames)
AllDriveNames = Space(Size)
Size = GetLogicalDriveStrings_(Size, @AllDriveNames)
*pAllDriveNames = @AllDriveNames
Count = Size / 4
For i = 1 To Count
AddElement(Drives())
Drives()\DriveLetter = LCase(PeekS(*pAllDriveNames, 3))
*pAllDriveNames + (4 * SizeOf(Character))
Drives()\NameOfVolume = Space(#MAX_PATH)
Drives()\DriveType = GetDriveType_(@Drives()\DriveLetter)
If Drives()\DriveType = #DRIVE_FIXED
GetVolumeInformation_(Drives()\DriveLetter, Drives()\NameOfVolume, #MAX_PATH, 0, 0, 0, 0, 0)
EndIf
Next
EndProcedure
Debug CountDrives()
Debug "....."
SearchDrives()
ForEach Drives()
Debug Drives()\DriveLetter
Debug Drives()\DriveType
Debug Drives()\NameOfVolume
Debug "......."
Next
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: List Computer Drives and Volume Informations
Thanks Thomas, it gets local hard disks and USB external disks with its label name.
But, it does not take CD's in consideration???
But, it does not take CD's in consideration???
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: List Computer Drives and Volume Informations
The read from CD is to slow for my program but you can change this:
line 35:
line 35:
Code: Select all
If Drives()\DriveType = #DRIVE_FIXED Or Drives()\DriveType = #DRIVE_CDROM
GetVolumeInformation_(Drives()\DriveLetter, Drives()\NameOfVolume, #MAX_PATH, 0, 0, 0, 0, 0)
EndIf
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: List Computer Drives and Volume Informations
Works like a charm!
Now I have the Drive Letter, the Label Name, and the Drive Type. Is there also a variable for the Serial Number?
After that it will be complete I think
Or is there more to get? 

Now I have the Drive Letter, the Label Name, and the Drive Type. Is there also a variable for the Serial Number?
After that it will be complete I think


- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: List Computer Drives and Volume Informations
thxcharvista wrote:Works like a charm!![]()
I don't nowcharvista wrote:Or is there more to get?
Code: Select all
EnableExplicit
Structure DriveInfos
DriveLetter.s
DriveType.l
NameOfVolume.s
DriveSerial.s
EndStructure
Global NewList Drives.DriveInfos()
Procedure CountDrives()
Protected AllDriveNames.s, Size, i, *pAllDriveNames
Size = GetLogicalDriveStrings_(0, @AllDriveNames)
AllDriveNames = Space(Size)
Size = GetLogicalDriveStrings_(Size, @AllDriveNames)
ProcedureReturn Size / 4
EndProcedure
Procedure SearchDrives()
Protected AllDriveNames.s, Size, Count, i, *pAllDriveNames, lpVolumeSerialNumber
ClearList(Drives())
Size = GetLogicalDriveStrings_(0, @AllDriveNames)
AllDriveNames = Space(Size)
Size = GetLogicalDriveStrings_(Size, @AllDriveNames)
*pAllDriveNames = @AllDriveNames
Count = Size / 4
For i = 1 To Count
AddElement(Drives())
Drives()\DriveLetter = LCase(PeekS(*pAllDriveNames, 3))
*pAllDriveNames + (4 * SizeOf(Character))
Drives()\NameOfVolume = Space(#MAX_PATH)
Drives()\DriveType = GetDriveType_(@Drives()\DriveLetter)
If Drives()\DriveType = #DRIVE_FIXED Or Drives()\DriveType = #DRIVE_CDROM
GetVolumeInformation_(Drives()\DriveLetter, Drives()\NameOfVolume, #MAX_PATH, @lpVolumeSerialNumber, 0, 0, 0, 0)
EndIf
If Drives()\DriveType = #DRIVE_FIXED
Drives()\DriveSerial = Hex(PeekW(@lpVolumeSerialNumber + 2) & $FFFF) + "-" + Hex(PeekW(@lpVolumeSerialNumber) & $FFFF)
EndIf
Next
EndProcedure
Debug CountDrives()
Debug "....."
SearchDrives()
ForEach Drives()
Debug Drives()\DriveLetter
Debug Drives()\DriveType
Debug Drives()\NameOfVolume
Debug Drives()\DriveSerial
Debug "......."
Next
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: List Computer Drives and Volume Informations


It also works on CDs, but there, some attention should be paid. I have a CD put in drive D: and it returns its SSN. OK. But there is also a CDROM found in H:, which is not connected, but H: returns the SSN of D:.
If I remove the CD from D:, D: and H: both return the SSN of C:
I conclude that it is best to use the SSN only if a label is found on the CD, when the type is #DRIVE_CDROM.
Many thanks for your help, Thomas!
EDIT
I know why the Serial Number is incorrectly given.
The variable lpVolumeSerialNumber has to be set to 0 before calling the API GetVolumeInformation_()
Code: Select all
If Drives()\DriveType = #DRIVE_FIXED Or Drives()\DriveType = #DRIVE_CDROM
lpVolumeSerialNumber=0
GetVolumeInformation_(Drives()\DriveLetter, Drives()\NameOfVolume, #MAX_PATH, @lpVolumeSerialNumber, 0, 0, 0, 0)
Drives()\DriveSerial = Hex(PeekW(@lpVolumeSerialNumber + 2) & $FFFF) + "-" + Hex(PeekW(@lpVolumeSerialNumber) & $FFFF)
EndIf
Last edited by charvista on Sun Apr 22, 2012 12:31 am, edited 1 time in total.
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: List Computer Drives and Volume Informations
CD-ROMs to i couldn't say much, since I have a few years ago exploded a CD in the drives, I use a CD only once, in order to transfer it to the hard drive. Is a slow and loud medium.
Enough offtopic, back to linux
Enough offtopic, back to linux

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
