Solved

Processing all the files in a folder VB6

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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

14 Experts available now in Live!

Get 1:1 Help Now