List all USB drives to combobox
Posted
#1
(In Topic #1354)
Regular

which gives me the exact results. However I can't figure out how to incorporate it into a combobox. I did it with printers and that was great but try as i might i can't figure this one out. I SWEAR I took some time to work this one out, I'm not just running to this forum every time i encounter a problem.lsblk -o NAME,FSTYPE | awk '$2 == "" { print $0 }'
Anyway is this doable ?
Thanks in advance!
Posted
Regular

Posted
Regular

Posted
Guru

So it was about you "NOT reading the replies, nothing to do with if you had replied or not.
I did a google search on how to detect usb disks for you and came up with this after seeing that TRAN can define the usb disks.
So i make a shell command that runs lsblk to get the disk information of the usb disks it detects with it's previous lsblk call
to detect usb drives…
lsblk -o PATH,TRAN| grep usb
Code (gambas)
Posted
Regular

Posted
Regular

Posted
Regular

but nothing's coming up in the comboboxDim sReturn As String
Shell "IFS=$'\n'; for s in $(lsblk -o PATH,TRAN| grep usb); do lsblk -o 'MOUNTPOINT,SIZE' ${s%% *}|grep /; done" To sReturn
ComboBox1.List = Split(sReturn, "\n", Null, True)
I tried replacing the shell command with something different but still coming up empty.
I apologize if I@m doing your head in.
Posted
Guru

theyikes said
I've tried putting what i know about adding printers to a listbox but I'm coming up blank. Could you perhaps maybe help me out AGAIN!!!
For printers you can use..
Printer.List (gb.form.print)
/comp/gb.qt4/printer - Gambas Documentation
Code (gambas)
Posted
Guru

theyikes said
Hello again! Ok i tried what you gave me
but nothing's coming up in the comboboxDim sReturn As String
Shell "IFS=$'\n'; for s in $(lsblk -o PATH,TRAN| grep usb); do lsblk -o 'MOUNTPOINT,SIZE' ${s%% *}|grep /; done" To sReturn
ComboBox1.List = Split(sReturn, "\n", Null, True)
I tried replacing the shell command with something different but still coming up empty.
I apologize if I@m doing your head in.
Works fine here , it lists ALL my plugged in usb disk drives.
I take it you have usb disks plugged in?
Posted
Regular

Dim sReturn As String
Shell "lsblk | grep disk" To sReturn
ListBox1.Add(sReturn)
It's almost 100% accurate.
Thanks A MILLION for your help, Honestly there's isn't a snowballs chance in hell i could have done it without you.
Who knows maybe sometime in the distant future someone will stumble upon this and learn from it.
Cheers
Posted
Regular

Posted
Guru

theyikes said
BruceSteers I think i have it. I modded what you agve me and i ran it and i pretty much got what i was looking for. Here's what i came up with:
Dim sReturn As String
Shell "lsblk | grep disk" To sReturn
ListBox1.Add(sReturn)
It's almost 100% accurate.
Thanks A MILLION for your help, Honestly there's isn't a snowballs chance in hell i could have done it without you.
Who knows maybe sometime in the distant future someone will stumble upon this and learn from it.
Cheers
So you wasn't actually wanting USB drives like you asked for , you just wanted a list of all disks.
Yes let's hope they learn all they need to know.
you havent "modded" my code you just wrote your own, and your code is only adding one item , the entire list as one string.
Shell "lsblk | grep disk" To sReturn
ListBox1.Add(sReturn)
is that almost 100% accurate?
this would be what you want like in my previous code example before you wrote your own.
ListBox1.List = Split(sReturn,"\n", Null, True)
Posted
Regular

Posted
Guru

theyikes said
Ok that worked PERFECTLY !!!! I have to ask, how long have you been using Gambas?
Right now it feels like too long …
I don't know , it was gambas2 when I originally started.
Posted
Regular

Posted
Regular

Dim sReturn As String
Shell " lsblk –nodeps –paths –output NAME,TRAN | grep usb | awk '{print $1}' " To sReturn
ListBox1.List = Split(sReturn, "\n", Null, True)
it just gives me the list of physical drives without any text.
Thanks guys!!!
Posted
Regular

This code will enumerate all devices belonging to 'block' subsystem and omit partitions and loop devices:
Code (gambas)
- ' struct udev *udev_new(void)
- ' Create udev library context.
- ' struct udev_enumerate *udev_enumerate_new(struct udev *udev)
- ' Create, acquire and release a udev enumerate object.
- ' int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem)
- ' Filter for a subsystem of the device to include in the list.
- ' int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate)
- ' Query or modify a udev enumerate object.
- ' struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate)
- ' Query or modify a udev enumerate object.
- ' const char *udev_list_entry_get_name(struct udev_list_entry *list_entry)
- ' Iterate and access udev lists.
- ' struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath)
- ' Create, acquire and release a udev device object.
- ' const char *udev_device_get_devtype(struct udev_device *udev_device)
- ' Return a pointer to a constant string that describes the requested property.
- ' const char *udev_device_get_devnode(struct udev_device *udev_device)
- ' Returns the path to the device node itself in /dev.
- ' const char *udev_device_get_sysname(struct udev_device *udev_device)
- ' Return a pointer to a constant string that describes the requested property.
- ' const char *udev_device_get_devpath(struct udev_device *udev_device)
- ' Return a pointer to a constant string that describes the requested property.
- ' const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr)
- ' Return a pointer to a constant string that describes the requested property.
- ' struct udev_device *udev_device_unref(struct udev_device *udev_device)
- ' Drop a reference of a udev device.
- ' struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry)
- ' Iterate and access udev lists.
- ' struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate)
- ' Drop a reference of an enumeration context.
- ' struct udev *udev_unref(struct udev *udev)
- ' Drop a reference of the udev library context.
- udev = udev_new()
- enu = udev_enumerate_new(udev)
- udev_enumerate_add_match_subsystem(enu, "block")
- udev_enumerate_scan_devices(enu)
- lst = udev_enumerate_get_list_entry(enu)
- path = udev_list_entry_get_name(lst)
- dev = udev_device_new_from_syspath(udev, path)
- tmp = udev_device_get_sysattr_value(dev, "size")
- tmp = udev_device_get_sysattr_value(dev, "queue/logical_block_size")
- udev_device_unref(dev)
- lst = udev_list_entry_get_next(lst)
- udev_enumerate_unref(enu)
- udev_unref(udev)
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
1 guest and 0 members have just viewed this.


