Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 DTS: Looping through files in folder..

Author  Topic 

krishnan
Starting Member

3 Posts

Posted - 2002-05-13 : 12:13:38
Hi,

Iam looping through the file in folder and changing the datasource dynamically.

Iam using the file system object. The problem is if i see the handle count in task manager it careateone handle for every file in the folder. And hence as the no of files are processed my package execution is going slower.

Is there any way I can create the object gloablly as i do with the variable.

The folllowing is the code to get the next file..

Option Explicit

Function Main()
' Declare FSO Related Variables
Dim sFolder
Dim fso
Dim fsoFolder
Dim fsoFilesCollection
Dim fsoFile
Dim sFileName
'Declare PKG Variables
Dim oPKG
Dim oConnection
Dim lTextStream

' Get Package Object
Set oPKG = DTSGlobalVariables.Parent

' Get Source Connection Object
Set oConnection = oPKG.Connections("TextFileConnection")

' Import Folder read from global variable
sFolder = DTSGlobalVariables("ImportFolder")


Set fso = CreateObject("Scripting.FileSystemObject")
Set fsoFolder = fso.GetFolder(sFolder)

Dim bFound ' Used to exclude files previously exported
bFound = False

For Each fsoFile in fsoFolder.Files
sFileName = sFolder & fsoFile.Name
If oConnection.DataSource = sFileName Then
bFound = True
ElseIf bFound = True Then ' New file found
oConnection.DataSource = sFileName
Set lTextStream = fso.OpenTextFile(fsoFile.Path)
DTSGlobalVariables("FileDump") = lTextStream.ReadAll
lTextStream.close
DTSGlobalVariables("FILENAME") = fsoFile.Name
' Set Pump Step to waiting
oPKG.Steps("DTSStep_DTSDataPumpTask_1") _
.ExecutionStatus = DTSStepExecStat_Waiting
Exit For
End If
Next
set fso=nothing
Set fsoFolder=Nothing
Set fsoFile = Nothing
msgbox fsofile.name

Set oPKG=Nothing
Set oConnection=Nothing

Main = DTSTaskExecResult_Success
End Function




Thanks,
Sajai.

   

- Advertisement -