PDA

View Full Version : List all files in a folder or import filenames into a merged document



pc_doc2001
09-15-2011, 11:56 AM
I have a folder with about 16,000 folders in it. The folder was created by a vb6 application written by a friend of mine. He now hates the owner of the lawnmower shop he wrote the application for; so he is of no help. I need to list all of the filename as they are the work order invoice numbers and counter sale invoices, (the work order folders are named after the work order number and they are ascii tab delimted text type files that contain all of the users data and order information but do not contain the invoice number when you open them in notepad). Then there are folders which are named by the 7 digit of 10 digit telephone number and these files contain the work order number or numbers associated with this telephone number. (The data in these folders is also in ascii tab deleimited form) I did a dos rename (ren c:\data*.* *.*.tsv) command on the files and gave them all a .tsv extension that I got from Google (such a reliable source).:help I need to import a list of the names of these files so that I can use the original names as the id for the original records. hopefully without the .tsv extension)

mancubus
09-15-2011, 02:23 PM
hi.
wellcome to VBAX.

if you are using office 2003 or earlier:
http://www.vbaexpress.com/kb/getarticle.php?kb_id=837

or

Sub ListFilesInFolder()

Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim ws As Worksheet
Dim LR As Long

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set ws = Worksheets.Add

Set oFolder = oFSO.GetFolder("C:\MyDocuments\MyFiles\")
ws.Cells(1, 1).Value = "Files in the Folder"

LR = 2
For Each oFile In oFolder.Files
ws.Cells(LR, 1).Value = oFile.Name
LR = LR + 1
Next

End Sub