Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Nov 21, 2017 12:45 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: File names into listbox?
PostPosted: Sat May 11, 2013 10:58 am 
Offline

Joined: Fri Jun 05, 2009 4:54 pm
Posts: 484
Location: London, England
Hi all,
I am trying to get a listbox to display rows populated with the names of all files in a particular folder.

I saw a couple of posts (I think one was from Kem Tekinay), and tried to combine them and ended up with the code below.

Could someone please tell me if this looks correct and would work.

Dim f As FolderItem
f=getfolderitem("pathToMyFolder")

Dim filetype() As String
filetype = Array(".txt",".rtf")

Dim fileext As String

Dim i As Integer

dim fileList() as FolderItem

dim folderCount as integer = f.Count

for i = 1 to folderCount
fileList.Append f.Item( i )
next
for i = 0 to fileList.Ubound
dim thisFile as FolderItem = fileList( i )
dim thisName as string = thisFile.Name
For Each fileext In filetype
dim thisExt as string = thisName.Right( fileext.Len )
if thisExt = fileext then
ListBox1.AddRow thisName
end if
next
next


Thank you all in advance.

_________________
RealStudio Professional Edition 2012 r2
Developing on OS X 10.8 (Mountain Lion)
Deploying on Windows XP / Vista / 7 / 8


Top
 Profile  
Reply with quote  
 Post subject: Re: File names into listbox?
PostPosted: Sat May 11, 2013 3:59 pm 
Offline
User avatar

Joined: Fri Sep 30, 2005 11:48 am
Posts: 3554
Location: Lenexa, KS
Looks like it will work.

_________________
Bob K.

A blog about being a Real Studio/Xojo developer at http://www.bkeeneybriefs.com


Top
 Profile  
Reply with quote  
 Post subject: Re: File names into listbox?
PostPosted: Sun May 12, 2013 4:38 am 
Offline

Joined: Fri Jun 05, 2009 4:54 pm
Posts: 484
Location: London, England
Thanks.

_________________
RealStudio Professional Edition 2012 r2
Developing on OS X 10.8 (Mountain Lion)
Deploying on Windows XP / Vista / 7 / 8


Top
 Profile  
Reply with quote  
 Post subject: Re: File names into listbox?
PostPosted: Sun May 12, 2013 5:04 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
You may find it is incredibly slow on Windows with folders that have many files in them.
If that is the case, consider shelling out a DIR command, and piping that to a text file.

(You may need to do two, one for TXT and one for RTF)

DIR C:\myfoldername\*.RTF > C:\somewritablefolder\RTFFILES.txt

If you do that, you get a text file that has already eliminated all but files that end in RTF.
Just open the text file and throw it at your listbox.


Top
 Profile  
Reply with quote  
 Post subject: Re: File names into listbox?
PostPosted: Sun May 12, 2013 8:10 am 
Offline

Joined: Fri Jun 05, 2009 4:54 pm
Posts: 484
Location: London, England
When you say "slow with a lot of files", how many files do you consider to be a lot?

_________________
RealStudio Professional Edition 2012 r2
Developing on OS X 10.8 (Mountain Lion)
Deploying on Windows XP / Vista / 7 / 8


Top
 Profile  
Reply with quote  
 Post subject: Re: File names into listbox?
PostPosted: Sun May 12, 2013 9:35 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Not sure: this is mostly hearsay/recollecting old posts

Check out this link, for example
viewtopic.php?f=7&t=42126&hilit=slow+directory


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group