Consulting

Results 1 to 2 of 2

Thread: List all files in a folder or import filenames into a merged document

  1. #1

    List all files in a folder or import filenames into a merged document

    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). 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)

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi.
    wellcome to VBAX.

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

    or
    [VBA]
    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
    [/VBA]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •