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)
 Check file size

Author  Topic 

roxysbrian
Starting Member

2 Posts

Posted - 2008-06-30 : 14:17:54
I'm new to DTS and VB scripting so please bear with me. Another company had setup a DTS script in SQL 2000 to retrieve pipe delimited text files, import them into a database then move them to a completed folder. I'm trying to automate this script but the problem I'm running into is that some of the files are empty and only have the end of character in the file and it throws an error and stops. The script also checks to see if there are multiple files in the folder to be processed as well. Is there a way that I can have the script check the folder for files that are empty and have them moved to the completed folder and not be processed by the rest of the script?

Here is the part of the script that starts the loop and checks for multiple files:


' 246 (Begin Loop)
Option Explicit

Function Main()

dim pkg
dim conTextFile
dim stpEnterLoop
dim stpFinished

set pkg = DTSGlobalVariables.Parent
set stpEnterLoop = pkg.Steps("DTSStep_DTSDataPumpTask_1")
set stpFinished = pkg.Steps("DTSStep_DTSActiveScriptTask_5")
set conTextFile = pkg.Connections("Text File (Source)")

' We want to continue with the loop only of there are more
' than 1 text file in the directory. If the function ShouldILoop
' returns true then we disable the step that takes us out of the package
' and continue processing

if ShouldILoop = True then
stpEnterLoop.DisableStep = False
stpFinished.DisableStep = True
conTextFile.DataSource = DTSGlobalVariables("gv_FileFullName").Value
stpEnterLoop.ExecutionStatus = DTSStepExecStat_Waiting
else
stpEnterLoop.DisableStep =True
stpFinished.DisableStep = False
stpFinished.ExecutionStatus = DTSStepExecStat_Waiting
End if

Main = DTSTaskExecResult_Success
End Function


Function ShouldILoop

dim fso
dim fil
dim fold
dim pkg
dim counter


set pkg = DTSGlobalVariables.Parent
set fso = CREATEOBJECT("Scripting.FileSystemObject")

set fold = fso.GetFolder(DTSGlobalVariables("gv_FileLocation").Value)

counter = fold.files.count

'So long as there is more than 1 file carry on

if counter >= 1 then

for each fil in fold.Files
DTSGlobalVariables("gv_FileFullName").Value = fil.path
ShouldILoop = CBool(True)
Next

else
ShouldILoop = CBool(False)
End if

End Function


Any help would be appreciated.

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-01 : 01:28:04
see this:-
http://www.sqldts.com/292.aspx
Go to Top of Page

roxysbrian
Starting Member

2 Posts

Posted - 2008-07-01 : 17:28:18
I saw that in another post but it doesn't really help as I have almost no scripting experience. Funny thing is, I was looking around on that site and found the very DTS package that we have: http://www.sqldts.com/246.aspx. The problem is, is that I have no idea where to place the check file size function as I said above, I'm not a scripter just trying to modify someone elses script to my life a little easier.

Thanks
Go to Top of Page
   

- Advertisement -