|
-
Sep 27th, 2004, 01:49 PM
#1
Thread Starter
Frenzied Member
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.
-
Sep 27th, 2004, 02:05 PM
#2
Frenzied Member
use a file list box and get rid of header_ through code
-
Sep 27th, 2004, 02:06 PM
#3
here is a quick sample for you ober:
VB Code:
Private Sub Command1_Click()
'============================
Dim sPath$, sFile$, pos%
Dim sItem$
sPath = "c:\temp\"
sFile = Dir(sPath, vbNormal)
Do While sFile <> ""
If sFile <> "." And sFile <> ".." Then
If UCase(Right(sPath & sFile, 4)) = ".DAT" Then
pos = InStr(1, sPath & sFile, "_")
sFile = Mid(sPath & sFile, pos + 1, InStr(pos + 1, sPath & sFile, ".") - pos - 1)
Combo1.AddItem sFile
End If
End If
sFile = Dir
Loop
End Sub
-
Sep 27th, 2004, 02:20 PM
#4
Thread Starter
Frenzied Member
Thanks, but I did some more searching and ended up with this:
VB Code:
Dim sFilename As String
sFilename = Dir("C:\Durb\header_*.dat")
Do While sFilename <> ""
' 11 = "header_" and ".dat"
cboTests.AddItem Mid(sFilename, 8, Len(sFilename) - 11)
sFilename = Dir
Loop
-
Sep 27th, 2004, 02:47 PM
#5
.. as long as it works for you ... but KIM that if you change directory and/or file name - your code will fail.
Cheers
-
Sep 27th, 2004, 02:48 PM
#6
Thread Starter
Frenzied Member
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.
-
Sep 27th, 2004, 02:54 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|