Selecting (Choosing) Folders and listing files to a listbox
Moderator: Rathinagiri
Selecting (Choosing) Folders and listing files to a listbox
Does anyone have a small piece of code for selecting a folder using a GetFolder GUI and sending the file listing in that folder to a listbox?
_________________
Sincerely,
Mike
Sincerely,
Mike
Re: Selecting (Choosing) Folders and listing files to a list
OK I think I got it. I kept trying to do it with
aadd or afill but both those methods didn't work. I left here the small bit of code I used.
*Made an edit to the code and added an IF condition because the first item in the listbox was always blank for some reason. Who knows. If anyone knows why it wouldn't work without the manually adding an entry into the first array position give me a shout.
aadd or afill but both those methods didn't work. I left here the small bit of code I used.
Code: Select all
*ChooseInput is a text control which got it's value from the GetFolder function
local aDir := Directory(Main.ChooseInput.Value+"\*.*")
local x
For x:=1 to len(aDir)
if x = 1
Main.afiles.Item(1):=adir[x,1]
else
Main.afiles.AddItem(adir[x,1])
end if
Next
_________________
Sincerely,
Mike
Sincerely,
Mike
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: Selecting (Choosing) Folders and listing files to a list
Hi Mike
Since you did'nt give a complete (SSW) code, sadly I don't understood your problem(s)
But this prg works well:
I hope that it help you.
Regards
--
Esgici
Since you did'nt give a complete (SSW) code, sadly I don't understood your problem(s)
But this prg works well:
Code: Select all
#include <hmg.ch>
PROCEDURE MAIN()
DEFINE WINDOW frmTestDirList;
AT 0, 0;
WIDTH 553 ;
HEIGHT 554 ;
TITLE "Test DIR List" ;
MAIN ;
ON INIT FillDirList()
@ 10, 100 BUTTON btnReLoad CAPTION "Re-Load" ACTION FillDirList()
@ 100, 100 LISTBOX lstbxDirList WIDTH 200 HEIGHT 200
END WINDOW // frmTestDirList
frmTestDirList.Center
frmTestDirList.Activate
RETURN // MAIN()
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PROCEDURE FillDirList()
LOCAL cDIRName := GetFolder( "Choose a folder" )
LOCAL aDirList := {}
LOCAL nDirElemNo :=0
IF !EMPTY( cDIRName )
aDirList := Directory( cDIRName )
IF EMPTY( aDirList )
MsgInfo( cDIRName + CRLF + " This folder doesn't contains ordinary file")
ELSE
frmTestDirList.lstbxDirList.DeleteAllItems()
FOR nDirElemNo := 1 to LEN( aDirList )
frmTestDirList.lstbxDirList.AddItem( aDirList[ nDirElemNo, 1 ] )
NEXT
ENDIF EMPTY( aDirList )
ENDIF !EMPTY( cDIRName )
RETURN // FillDirList()
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Regards
--
Esgici
Viva INTERNATIONAL HMG
Re: Selecting (Choosing) Folders and listing files to a list
Excellent, yes thanks, I just figured it out before you posted it.
I am curious though how come you added this line
Why does the listbox create an empty item on initialization?
That's not important but I figured I would ask.
Thanks again!
I am curious though how come you added this line
Code: Select all
frmTestDirList.lstbxDirList.DeleteAllItems()
That's not important but I figured I would ask.
Thanks again!
_________________
Sincerely,
Mike
Sincerely,
Mike
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: Selecting (Choosing) Folders and listing files to a list
If you don't delete the items in the listbox, every time when you click the button, the items are added last to the listbox.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: Selecting (Choosing) Folders and listing files to a list
You are right, it's unnecessary on initialization, required when call by button.nassausky wrote:... I figured I would ask.
But it's also unnecessary testing calling sequence ( called by ON INIT or BUTTON ?) and seperating process ( emty or not) within sub-procedure.
It isn't ?
Regards
--
Esgici
Viva INTERNATIONAL HMG