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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Not Found Problem. 1

Status
Not open for further replies.
Mar 12, 2003
678
US
I have the following code running as an ActiveX Script using DTS. The problem that I run into is that sometimes the file exists but has no data. Therefore a size of 0. When I run the code it comes back as "Object Required:sFilename" error on line 11. However if I remove the size condition the code runs fine. I am using the result to determine my next task.

Function Main()
Dim oFSO, sFileName

' Get the name of the file from the Connection "Text File (Source)"
sFilename = DTSGlobalVariables.Parent.Connections("GDM RDP").DataSource

Set oFSO = CreateObject("Scripting.FileSystemObject")


' Check for file and return appropriate result
If oFSO.FileExists(sFilename) Then
If sFilename.size >0 Then
Main = DTSTaskExecResult_Success
Else
Main = DTSTaskExecResult_Failure
End If
Else
Main = DTSTaskExecResult_Failure
End If

Set oFSO = Nothing

End Function

 
try something like:
Code:
Function Main()
        Dim oFSO, sFileName
        [b]Dim dFileName[/b]


        ' Get the name of the file from the Connection "Text File (Source)"
        sFilename = DTSGlobalVariables.Parent.Connections("GDM RDP").DataSource

        Set oFSO = CreateObject("Scripting.FileSystemObject")
    
    
        ' Check for file and return appropriate result
        If oFSO.FileExists(sFilename) Then
          [b]Set dFileName = oFSO.GetFile(sFileName)[/b]
            If [b]dFilename[/b].size >0 Then 
              Main = DTSTaskExecResult_Success
            Else 
              Main = DTSTaskExecResult_Failure
            End If
        Else
          Main = DTSTaskExecResult_Failure
        End If
        
        Set oFSO = Nothing
        Set dFileName = Nothing
    
End Function
 
That did it. I knew I should have came to the forum first before wasting three hours.
 
well, you learned your lesson then didn't you?? ;-) Glad it worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top