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

File Names 2

Status
Not open for further replies.

luceze

Programmer
Apr 26, 2001
842
0
0
US
Is there a way to populate a table with the file names from a directory. I tried messing with the Dir function but could not get it to work.

Thanks,

Eric
 
use the DOS redirection symbol ">>" to direct the listing to a text file, e.g.

DIR *.* >> FILENAMES.TXT

Then you can import this file into a table.
 
What doesn't work for you with the Dir() function? Try adapting the following code.
Code:
Dim sFile As String
  
sFile = Dir("C:\*.*", vbNormal)
Do While sFile & &quot;&quot; <> &quot;&quot;
  Debug.Print sFile
  sFile = Dir()
Loop
 
jfischer,

I tried it but I'm not sure what's supposed to happen. How should I call the function and how do I display the output. Here's what I used:

Public Function FileName()


Dim sfile As String

sfile = Dir(&quot;C:\winnt\profiles\ExcelFiles\*.xls&quot;, vbNormal)
Do While sfile & &quot;&quot; <> &quot;&quot;
Debug.Print sfile
sfile = Dir()
Loop

End Function
 
That code does not populate a table; it just prints the file.
 
This is just a code sample. You need to adapt it to your situation. To test the sample code as you entered it:

1) Open a Debug (Immediate) window [press Ctrl-G].
2) Type the following:
Code:
? FileName()
If the function runs properly you should see a list of Excel spreadsheets appear in the Debug window.

Your next step is to change the Debug.Print statement into the appropriate statements to add records to your file name table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top