Solved

Processing all the files in a folder VB6

Posted on 2003-11-14
4
520 Views
Last Modified: 2010-05-01
Hi,

I have written a program in VB6 that looks in a specified folder and opens a text file and processes the records in this file. At the moment my program only processes a file with a defined name of 'TradeMatch.txt'.

The issue I have is that the folder may have 10 files in (at the same time) and I need to process all 10. The file naming convention of any file placed is 'TradeMatchDDMMYYHHMMSS.txt'

How can I change my program so it will process all files in the folder where the filename starts with ‘TradeMatch’….?

Thanks Ian Carrick
0
Comment
Question by:ISC
  • 2
4 Comments
 
LVL 3

Assisted Solution

by:monvelasquez
monvelasquez earned 250 total points
ID: 9746084
use the dir command

--[CODE]--------------------------------------------------------------
Dim filename As String

filename = Dir("C:\MyFolder\TradeMatch*.txt", vbNormal)
Do While filename <> ""

  ' File processing here
  Debug.Print filename

  filename = Dir
Loop

--[/CODE]-------------------------------------------------------------
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 250 total points
ID: 9746092
Hi ISC,

Quite simple really:

Dim strFile As String
strFile = Dir("TradeMatch*.txt")
Do While strFile <> ""
  ProcessFile strFile
  strFile = Dir("TradeMatch*.txt")
Loop  

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 9746098
Ooops a bit to quick then, the second strFile=Dir(...) should just be strFile = Dir()

0
 
LVL 1

Expert Comment

by:Shaztronics
ID: 9746257
------------------------------------------------------------------------
Const DDL_READWRITE = &H0
Const LB_DIR = &H18D
Dim sPattern as String
Dim counterx as Integer

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long

Private Sub Command1_Click()
sPattern = "C:\<Path>\TradeMatch*.txt"

SendMessage List1.hwnd, LB_DIR, DDL_READWRITE, sPattern
End Sub
------------------------------------------------------------------------
Assuming a list box(Make it hidden if u want) to list the files, all files will go in the list starting with TradeMatch and with the extension ".txt". eg
TradeMatch11111.txt
TradeMatch22222.txt
TradeMatch33333.txt

Then just process them by adding the list item with the path...
------------------------------------------------------------------------
counterx = 0
For counterx to list1.listcount
list1.list(counterx) = "<path>" & list1.list(counterx)
counterx = counterx + 1
Loop
------------------------------------------------------------------------
Then process the files...
------------------------------------------------------------------------
counterx = 0
For counterx to list1.listcount
<Process Code>
counterx = counterx + 1
Loop
------------------------------------------------------------------------
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now