?
Solved

Processing all the files in a folder VB6

Posted on 2003-11-14
4
Medium Priority
?
525 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Assisted Solution

by:monvelasquez
monvelasquez earned 1000 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 1000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

765 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