LB Booster
« Listing a directory in a listbox »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:38am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Listing a directory in a listbox  (Read 600 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Listing a directory in a listbox
« Thread started on: Sep 21st, 2015, 09:00am »

Listing the contents of a disk directory in a LISTBOX is trivial, because it's a native function of Windows - although not many people seem to realise that:

Code:
    listbox #w.lb, dummy$(), [click], 10, 10, 280, 300
    open "Directory listing" for window as #w
    hlb = hwnd(#w.lb)
    afsp$ = "C:\Windows\*.*"
    calldll #user32, "SendMessageA", hlb as ulong, _LB_DIR as long, _
        0 as long, afsp$ as ptr, ret as long
    wait 

The API gives you control over what is listed, so for example if you want to include sub-directories as well as files:

Code:
    listbox #w.lb, dummy$(), [click], 10, 10, 280, 300
    stylebits #w.lb _LBS_SORT,0,0,0
    open "Directory listing" for window as #w
    hlb = hwnd(#w.lb)
    afsp$ = "C:\Windows\*.*"
    calldll #user32, "SendMessageA", hlb as ulong, _LB_DIR as long, _
        _DDL_DIRECTORY as long, afsp$ as ptr, ret as long
    wait 

If you prefer the sub-directories at the top, you can do that too:

Code:
    listbox #w.lb, dummy$(), [click], 10, 10, 280, 300
    open "Directory listing" for window as #w
    hlb = hwnd(#w.lb)
    afsp$ = "C:\Windows\*.*"
    calldll #user32, "SendMessageA", hlb as ulong, _LB_DIR as long, _
      _DDL_DIRECTORY or _DDL_EXCLUSIVE as long, afsp$ as ptr, ret as long
    calldll #user32, "SendMessageA", hlb as ulong, _LB_DIR as long, _
      0 as long, afsp$ as ptr, ret as long
    wait 

Richard.
« Last Edit: Sep 21st, 2015, 10:25am by Richard Russell » User IP Logged

Cor
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 8
xx Re: Listing a directory in a listbox
« Reply #1 on: Nov 21st, 2015, 09:26am »

Richard,

Can this code be modified so that its output goes to an array? And can that array be populated such that each subdirectory in it is followed by its contents?

Great code. Just what I needed at this moment. Thank you.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Listing a directory in a listbox
« Reply #2 on: Nov 21st, 2015, 09:44am »

on Nov 21st, 2015, 09:26am, Cor wrote:
Can this code be modified so that its output goes to an array?

Well you could code a loop to read the contents of the listbox into an array, either by using the SELECTINDEX and SELECTION? commands or by using the Windows API (LB_GETTEXT message). But wouldn't it be easier to use the FILES statement and simply arrange to pass the same path and filter parameters as you used for the listbox?

Quote:
And can that array be populated such that each subdirectory in it is followed by its contents?

There are examples of recursive use of the FILES statement to recover the contents of sub-directories. A search of the usual LB code repositories should be fruitful.

Richard.

User IP Logged

Cor
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 8
xx Re: Listing a directory in a listbox
« Reply #3 on: Nov 21st, 2015, 1:43pm »

Looked for and found a good example of what I want. Thanks.

Cor
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls