Solved

Processing all the files in a folder VB6

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

920 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

19 Experts available now in Live!

Get 1:1 Help Now