How to check if the file is empty
Hi all,In my SSIS I am populating a table from a file but before I do anything, at the beginning I'd like to check if there is any data in the file and I am guessing a Script Task would do the job. However I have no clue about the code itself.Can anyoneknow acode to see if the file is empty or not?Thanks!
May 13th, 2009 4:27am

You could use the File Properties Task, or a Script. If you use a Script, you would have to pass in the file name as a variable, or hard-code it inside the script. You would use the System.IO namespace, in particular, the FileInfo classand it's Length property.Update 2009-08-07: I have just constructed a new File Properties Task (the above Task is semi-free from PragmaticWorks, and is only available for 2005). It's available on CodePlex for SSIS 2005 and 2008.
Free Windows Admin Tool Kit Click here and download it now
May 13th, 2009 6:12am

Hi, Please modify the below code as you required. Dim strFilePath As String strFilePath = Dts.Variables("Var_FilePath").Value.ToString Dim objFSO As Object Dim objFile As Object objFSO = CreateObject("Scripting.FileSystemObject") objFile = objFSO.GetFile(strFilePath) If objFile.Size > 0 Then Dts.Variables("Var_Status_InvalidFileDetailData").Value = True End If Let me know if any issue with this. Thanks- Let us TRY this
May 13th, 2009 6:35am

Hi,Please modify the below code as you required. Dim strFilePath As String strFilePath = Dts.Variables("Var_FilePath").Value.ToString Dim objFSO As Object Dim objFile As Object objFSO = CreateObject("Scripting.FileSystemObject") objFile = objFSO.GetFile(strFilePath) If objFile.Size > 0 Then Dts.Variables("Var_Status_InvalidFileDetailData").Value = True End IfLet me know if any issue with this.Thanks- Let us TRY this Will give it a tryThank you very much for your time
Free Windows Admin Tool Kit Click here and download it now
May 13th, 2009 6:48am

Here is a C# Script Task example of getting the file size (and some other file properties): http://microsoft-ssis.blogspot.com/2011/03/get-file-properties-with-ssis.htmlPlease mark the post as answered if it answers your question | My SSIS Blog: http://microsoft-ssis.blogspot.com
March 13th, 2011 4:23pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics