Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read the files from directory

Status
Not open for further replies.

techipa

Programmer
Feb 12, 2007
85
US
Hi All,

I am very new to VB programming. What I need to know is how do I wriet the VBScript to read the just the CSV files from a directory.

I have to code this in ActiveX script task in DTS. Each CSV fiel from that folder should be imported in SQL table.

Can anyone advice me on how to implement this task?

Thanks in advace,
-techiPA
 
Lookup the help on FileSystemObject. There are a few examples there on how to do all sorts with the file system including reading files.
 
This should get your started, it will look in a directory for CSV files.

Code:
Option Explicit
'On Error Resume Next

Dim objFSO, objFolder, objFile, strDirPath, strFileName, strExtension

strDirPath = "c:\temp"
strExtension = "csv"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strDirPath)

For Each objFile In objFolder.Files
	strFileName = UCase(objFile.Name)
	If Right(strFileName, Len(strFileName) - InStrRev(strFileName, ".")) = UCase(strExtension) Then
		WScript.Echo strFileName
	End If
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Thanks dm4ever,

I use your code to implement my logic.

Thanks,
-techiPA


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top