Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically scan files in a folder

Status
Not open for further replies.

johann59

Programmer
Mar 3, 2005
32
US
When I start my program in VFP I would like it to automatically scan the contents of a specific folder and if any files in there, load them into a ListBox. Any suggestions would be appreciated. Thanks.
 
You can ue ADIR() to scan a folder and get the files into an array. You can then use the array to populate a listbox:

Code:
LOCAL ARRAY laFiles(1)
LOCAL lnCount, lnI

lnCount = ADIR(laFiles, "c:\MyFolder")

THISFORM.lstMyListBox.RowSourceType = 0
FOR lnI = 1 TO lnCount
  THISFORM.lstMyListBox.AddItem(JUSTFNAME(laFiles), lnI, 1)
ENDFOR
THISFORM.lstMyListBox.ListIndex = 1

I haven't tested this, but it should give you the general idea.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Is their any reason rowsourcetype 7 (files) won't do the job?

Files Source Type
You can populate a list box or combo box with the names of files from the current directory. The list also contains options for you to choose a different drive and directory to display file names from.

To populate the control with file names from a directory
Set RowSourceType to 7 (Files).

Set RowSource by specifying a file skeleton or mask, such as *.* or *.fileExt.

For example, the following lines of code set RowSourceType to 7 to indicate that the source type is files and specifies a file skeleton for RowSource:

Form1.lstMyList.RowSourceType = 7
Form1.lstMyList.RowSource = "*.*"

If you want to use a folder other then the current folder just put the path name in the rowsource property.



Alan
 
Alan,

I didn't suggest using RowSourceType = 7, mainly because I don't like the way the files appear in the listbox with this RowSourceType. It looks a bit DOS-like, if you know what I mean. In particular, users might now know that [..] means the parent directory.

But that's just a personal preference. Your suggestion has the advantage of letting the user navigate the directory tree. Then again, if that was a requirement, it would be more Windows-like to use a File Open dialogue perhaps.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike, Alan, thank you very much, that did it. I appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top