Solved

Processing all the files in a folder VB6

Posted on 2003-11-14
4
522 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 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