Link to home
Start Free TrialLog in
Avatar of dupont2406
dupont2406Flag for United States of America

asked on

Import all files in a directory in Visual Basic

I have a program that imports data from a text file.  I am able to import the data from the specific file by specifying the exact path.  I would like to know how to import each file in the directory regardless of the name of the file.  After the file has been imported I would like it deleted.  

Directory to import from is c:\importfolder

Thank You
Avatar of [ fanpages ]
[ fanpages ]

Here's one method...

Dim strFile As String

strFile = Dir$("c:\yourfolder\")

While Len(Trim$(strFile)) > 0

    ' Import your file here based on the filename being in the string variable strFile

    ' YOUR CODE HERE

    ' After processing, delete the specific file & see if there are any more...

    Kill strFile

    strFile = Dir$()

Wend



BFN,

fp.
Sorry, for:

strFile = Dir$("c:\yourfolder\")

Read:

strFile = Dir$("c:\importfolder\")
Apologies again,

Replace:
strFile = Dir$("c:\yourfolder\")

With:
strFile = Dir$("c:\importfolder\*.*")


(It's 3:28am local time, btw!)
ASKER CERTIFIED SOLUTION
Avatar of [ fanpages ]
[ fanpages ]

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dupont2406

ASKER

That works

Thank You
You're welcome.

Thanks for closing the question so promptly.

BFN,

fp.