Real Software Forums
http://forums.realsoftware.com/

File names into listbox?
http://forums.realsoftware.com/viewtopic.php?f=10&t=47850
Page 1 of 1

Author:  RicSum [ Sat May 11, 2013 10:58 am ]
Post subject:  File names into listbox?

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.

Author:  Bob Keeney [ Sat May 11, 2013 3:59 pm ]
Post subject:  Re: File names into listbox?

Looks like it will work.

Author:  RicSum [ Sun May 12, 2013 4:38 am ]
Post subject:  Re: File names into listbox?

Thanks.

Author:  kermit [ Sun May 12, 2013 5:04 am ]
Post subject:  Re: File names into listbox?

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.

Author:  RicSum [ Sun May 12, 2013 8:10 am ]
Post subject:  Re: File names into listbox?

When you say "slow with a lot of files", how many files do you consider to be a lot?

Author:  kermit [ Sun May 12, 2013 9:35 am ]
Post subject:  Re: File names into listbox?

Not sure: this is mostly hearsay/recollecting old posts

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

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/