Results 1 to 7 of 7

Thread: get file names from a folder [Resolved]

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Resolved get file names from a folder [Resolved]

    I have a bunch of files in a folder, and some of them are named "header_xxxx.dat". I want to get the "xxxx" part and put it in a combo box.

    I have no idea where to start on figuring this out, so I'd appreciate some guidance. Thanks in advance.

    I tried using a filelist box, but I want to filter out just the xxxx part, so that won't really do what I want.

    Help?
    Last edited by ober0330; Sep 27th, 2004 at 02:21 PM.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    use a file list box and get rid of header_ through code

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    here is a quick sample for you ober:
    VB Code:
    1. Private Sub Command1_Click()
    2. '============================
    3. Dim sPath$, sFile$, pos%
    4. Dim sItem$
    5.  
    6.     sPath = "c:\temp\"
    7.     sFile = Dir(sPath, vbNormal)
    8.     Do While sFile <> ""
    9.         If sFile <> "." And sFile <> ".." Then
    10.             If UCase(Right(sPath & sFile, 4)) = ".DAT" Then
    11.                 pos = InStr(1, sPath & sFile, "_")
    12.                 sFile = Mid(sPath & sFile, pos + 1, InStr(pos + 1, sPath & sFile, ".") - pos - 1)
    13.                 Combo1.AddItem sFile
    14.             End If
    15.         End If
    16.         sFile = Dir
    17.     Loop
    18.  
    19. End Sub

  4. #4

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Thanks, but I did some more searching and ended up with this:
    VB Code:
    1. Dim sFilename As String
    2.  
    3. sFilename = Dir("C:\Durb\header_*.dat")
    4.  
    5. Do While sFilename <> ""
    6.  
    7.   ' 11 = "header_" and ".dat"
    8.   cboTests.AddItem Mid(sFilename, 8, Len(sFilename) - 11)
    9.   sFilename = Dir
    10.  
    11. Loop
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    .. as long as it works for you ... but KIM that if you change directory and/or file name - your code will fail.

    Cheers

  6. #6

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Right... but the directory will never change for this app.... well, actually, I guess I'll just change it to App.Path. Thanks for the heads up.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Originally posted by ober0330
    ... will never change for this app.... well, actually, ...
    ... just what I was afraid of ...
    Although, if you ever decide to create a subfolder within that main and/or store some files of a different type then your code will fail as well so you will be forced to do something similar to what I posted for you. Read MSDN for more info on Dir function.

Posting Permissions

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



Click Here to Expand Forum to Full Width