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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing file names from within a folder

Status
Not open for further replies.

johnnyv

Programmer
Jul 13, 2001
216
0
0
CA
I have a folder containing 10 files. I know the location and name of the folder
1 can I use vb to find out the names of all 10 files with in the folder and assign them to 10 different variables within an variable array

2 if the user highlites 5 of the files from within the folder can I use vb to assign those 5 file names to variables within an array.
 
Are you using the VB File list box control. If so, then interface with it similar to how you would a listbox.

dim X as integer,FileArray() as string,pointer as integer
for x = 0 to file1.listcount-1
if file1.selected(x) then
redim preserve FileArray(0 to pointer)
FileArray(X) = File1.List(pointer)
pointer = pointer + 1
end if
next

If you are not using the file listbox then you could use the Dir() function, FileSystemObject, or a host of API calls to get the job done.
 
The easiest way to get filenames is the Dir function.
To get the filenames use
strFilename = Dir(Path)
the first time and for the other 9 files just:
strFilename = Dir

You can specify options to include hidden or system files etc in the initial Dir call. ex:
strFilename = Dir(Path, vbHidden & vbDirectory)
will also retrieve hidden files and directories.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top