List Drives with Free Space
-
collectordave
- Addict

- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
List Drives with Free Space
I am being a little dumb here I think.
Searched forum. Just need to list drives on computer with if possible the free space.
Tried using Explorer list gadget but no luck.
Cross platform if at all possible.
What am I missing?
regards
CD
Searched forum. Just need to list drives on computer with if possible the free space.
Tried using Explorer list gadget but no luck.
Cross platform if at all possible.
What am I missing?
regards
CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
- NicTheQuick
- Addict

- Posts: 1527
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: List Drives with Free Space
At first there is big difference between Windows, Linux and Mac. On Linux you probably have mounted a lot of filesystems. Some of them are real drives, but most of them are temporary filesystems or devices systems. It seems you want to list the block devices like mounted ISO, mounted SSDs or HDDs, maybe mounted network file systems or webdav mounts.
You can find information about all of these mount points either in /proc/mounts or /proc/self/mountinfo. I don't know if there is direct API to get these information.
As example this is my /proc/mounts:
You can find information about all of these mount points either in /proc/mounts or /proc/self/mountinfo. I don't know if there is direct API to get these information.
As example this is my /proc/mounts:
Code: Select all
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
udev /dev devtmpfs rw,nosuid,relatime,size=7967276k,nr_inodes=1991819,mode=755 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /run tmpfs rw,nosuid,noexec,relatime,size=1598532k,mode=755 0 0
/dev/sda1 / ext4 rw,noatime,errors=remount-ro 0 0
securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
tmpfs /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,mode=755 0 0
cgroup2 /sys/fs/cgroup/unified cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate 0 0
cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,xattr,name=systemd 0 0
pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0
bpf /sys/fs/bpf bpf rw,nosuid,nodev,noexec,relatime,mode=700 0 0
cgroup /sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0
cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0
cgroup /sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noexec,relatime,perf_event 0 0
cgroup /sys/fs/cgroup/pids cgroup rw,nosuid,nodev,noexec,relatime,pids 0 0
cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpu,cpuacct 0 0
cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0
cgroup /sys/fs/cgroup/rdma cgroup rw,nosuid,nodev,noexec,relatime,rdma 0 0
cgroup /sys/fs/cgroup/net_cls,net_prio cgroup rw,nosuid,nodev,noexec,relatime,net_cls,net_prio 0 0
cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0
cgroup /sys/fs/cgroup/hugetlb cgroup rw,nosuid,nodev,noexec,relatime,hugetlb 0 0
cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=34,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=13169 0 0
mqueue /dev/mqueue mqueue rw,relatime 0 0
hugetlbfs /dev/hugepages hugetlbfs rw,relatime,pagesize=2M 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0
configfs /sys/kernel/config configfs rw,relatime 0 0
tmpfs /tmp tmpfs rw,noatime 0 0
/dev/loop1 /snap/pycharm-community/155 squashfs ro,nodev,relatime 0 0
/dev/loop2 /snap/code/14 squashfs ro,nodev,relatime 0 0
/dev/loop4 /snap/gtk-common-themes/1313 squashfs ro,nodev,relatime 0 0
/dev/loop0 /snap/gnome-3-28-1804/67 squashfs ro,nodev,relatime 0 0
/dev/loop3 /snap/gping/13 squashfs ro,nodev,relatime 0 0
/dev/loop5 /snap/gnome-3-28-1804/71 squashfs ro,nodev,relatime 0 0
/dev/loop6 /snap/core/7396 squashfs ro,nodev,relatime 0 0
/dev/loop8 /snap/core18/1098 squashfs ro,nodev,relatime 0 0
/dev/loop10 /snap/code/15 squashfs ro,nodev,relatime 0 0
/dev/loop9 /snap/core/7713 squashfs ro,nodev,relatime 0 0
/dev/loop11 /snap/gnome-characters/317 squashfs ro,nodev,relatime 0 0
/dev/loop12 /snap/gnome-3-26-1604/90 squashfs ro,nodev,relatime 0 0
/dev/loop13 /snap/core18/1144 squashfs ro,nodev,relatime 0 0
/dev/loop15 /snap/gnome-characters/296 squashfs ro,nodev,relatime 0 0
/dev/loop16 /snap/gtk-common-themes/1198 squashfs ro,nodev,relatime 0 0
/dev/loop14 /snap/pycharm-community/150 squashfs ro,nodev,relatime 0 0
/dev/loop17 /snap/gnome-logs/73 squashfs ro,nodev,relatime 0 0
/dev/loop18 /snap/gnome-3-26-1604/92 squashfs ro,nodev,relatime 0 0
/dev/sda3 /media/nicolas/FastData ext4 rw,noatime 0 0
/dev/sdb1 /home ext4 rw,noatime 0 0
/dev/sdb1 /home/nicolas/ownCloud/workspace_avr ext4 rw,nosuid,nodev,noexec,noatime 0 0
/dev/sdb1 /home/nicolas/ownCloud/workspace_arm ext4 rw,nosuid,nodev,noexec,noatime 0 0
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=1598528k,mode=700,uid=1000,gid=1000 0 0
gvfsd-fuse /run/user/1000/gvfs fuse.gvfsd-fuse rw,nosuid,nodev,relatime,user_id=1000,group_id=1000 0 0
/dev/loop19 /snap/gnome-logs/81 squashfs ro,nodev,relatime 0 0The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
-
collectordave
- Addict

- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: List Drives with Free Space
Just need to list physical drives for user to choose.
It is for a backup system so can be limited to usb drives etc.
It is for a backup system so can be limited to usb drives etc.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Re: List Drives with Free Space
Based on:
http://forums.purebasic.com/english/vie ... 13&t=26763
Ref. https://msdn.microsoft.com/fr-fr/window ... p/aa364939
http://forums.purebasic.com/english/vie ... 13&t=26763
Code: Select all
For a = 65 To 90 : a$=Chr(a) + ":\"
Select GetDriveType_(a$)
Case #DRIVE_FIXED
Debug a$ + " HDD/SSD"
Case #DRIVE_REMOVABLE
Debug a$ + " USB"
EndSelect
NextCode: Select all
C:\ HDD/SSD
D:\ HDD/SSD
E:\ USB
Last edited by Marc56us on Wed Oct 02, 2019 3:48 pm, edited 1 time in total.
-
collectordave
- Addict

- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: List Drives with Free Space
Having some success on MAC with
Lists the drives and lets me pick one.
Anything similar in Windows?
Code: Select all
InitialPath$ = "/Volumes/" ; set initial path to display (could also be blank)
Path$ = PathRequester("Please choose your path", InitialPath$)
If Path$
MessageRequester("Information", "You have selected following path:"+Chr(10)+Path$, 0)
Else
MessageRequester("Information", "The requester was canceled.", 0)
EndIfAnything similar in Windows?
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
-
collectordave
- Addict

- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: List Drives with Free Space
A little more on the MAC.
Lists my drives and allows me to pick one then create a folder for backup. Rejects main drive as it needs permission.
Just do this on windows now.
Code: Select all
Global TopDriveFolder.s,SelectedDrive.s
TopDriveFolder = "/Volumes/"
If OpenWindow(0, 0, 0, 400, 200, "ExplorerListGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ExplorerListGadget(0, 10, 10, 380, 180, TopDriveFolder, #PB_Explorer_NoDirectoryChange|#PB_Explorer_NoParentFolder)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
SelectedDrive = TopDriveFolder + GetGadgetItemText(0,GetGadgetState(0))
If CreateDirectory(SelectedDrive + "/Test/") = 0
MessageRequester("Unable To Create Backup Folder!", "Please Choose Another Drive.",#PB_MessageRequester_Ok)
EndIf
EndIfJust do this on windows now.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Re: List Drives with Free Space
For Windows:collectordave wrote:need to list drives on computer with if possible the free space
Code: Select all
For d='A' To 'Z'
d$=Chr(d)+":\"
t=GetDriveType_(d$)
If t=#DRIVE_REMOVABLE Or t=#DRIVE_FIXED
If GetDiskFreeSpaceEx_(@d$,@free.q,@total.q,0)
Debug d$+" free bytes: "+Str(free)
EndIf
EndIf
Next
Re: List Drives with Free Space
I just created an include to determine the mounted drives: GetDrivesInfo() (Currently only Linux and Mac)
Besides:
Code: Select all
Structure DrivesListStruc
fsType$ ; devtmpfs, tmpfs, ext4, vfat
avail$ ; 1,6G, 300M
size$ ; 1,6G, 300M
target$ ; /, /tmp, /boot/efi, /run/media/username/medianame
EndStructure
NewList drivesList.DrivesListStruc()
GetDrivesInfo(drivesList())
Last edited by Sicro on Thu Oct 03, 2019 1:32 pm, edited 2 times in total.

Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
Re: List Drives with Free Space
Without API stuff:
Code: Select all
For Drive = 'A' To 'Z'
Dir = ExamineDirectory(#PB_Any, Chr(Drive) + ":/", "*")
If Dir
Debug Chr(Drive)
FinishDirectory(Dir)
EndIf
Next Drive
Re: List Drives with Free Space
Nice, infratec. 
Re: List Drives with Free Space
Did you see this post by Shardik ?collectordave wrote:Having some success on MAC with
viewtopic.php?p=415435#p415435
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
-
collectordave
- Addict

- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: List Drives with Free Space
No
Thanks for pointing me in the right direction.
CD
Thanks for pointing me in the right direction.
CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
-
Randy Walker
- Addict

- Posts: 1109
- Joined: Sun Jul 25, 2004 4:21 pm
- Location: USoA
Re: List Drives with Free Space
Very Nice! Thank you BarryG!!!BarryG wrote: Thu Oct 03, 2019 9:09 amFor Windows:collectordave wrote:need to list drives on computer with if possible the free space
Code: Select all
For d='A' To 'Z' d$=Chr(d)+":\" t=GetDriveType_(d$) If t=#DRIVE_REMOVABLE Or t=#DRIVE_FIXED If GetDiskFreeSpaceEx_(@d$,@free.q,@total.q,0) Debug d$+" free bytes: "+Str(free) EndIf EndIf Next
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy
I *never* claimed to be a programmer.
Re: List Drives with Free Space
I forgot about that post.
Glad I could help.


