need help with vb Script for checking if file exists using script task in ssis

Hi i am writing a script task in ssis. I need assistance in writing the script task. i googled it as i am newbie to scripting, i need help. So here is the code i got. but the thing is I dont want to hard code the file name because there are four files that exists with different numbers on it with the timestamp on it for that particular day. Can I do that at the point of file location in this script without hardcoding the file. i check this code but its poping up a window. I don't want to see any pop window instead send an email to concerned using send mail task in ssis. Suggest me how can I go about it and how do i know if files doesnt exist. if doesn't exist send an email that says doesnt exist .. Please help me in writing


using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.IO; 

namespace ST_d4b3389a51734caa85bb7d3b9a843c90.csproj
{
  [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
  public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
  {

    #region VSTA generated code
    enum ScriptResults
    {
      Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
      Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
    };
    #endregion

    

    public void Main()
    {

      //USe your folder and file name here to check if exists

      if (File.Exists(@"D:\\YOURFILEFOLDER\\Test.txt"))       -- [b]I need to check if four files are added dynamically or using wild card like * to imply that four files exists...[/b]
      {
        Dts.Variables["FileExtFlag"].Value = 1;
        MessageBox.Show(Dts.Variables["FileExtFlag"].Value.ToString()); //comment out this line, just for testing the value of variable
      }
      else
      {
        Dts.Variables["FileExtFlag"].Value = 0;
        MessageBox.Show(Dts.Variables["FileExtFlag"].Value.ToString()); //comment out , just to check value
      }
      // TODO: Add your code here
      Dts.TaskResult = (int)ScriptResults.Success;
    }
  }
}

Open in new window

srionline2k6Asked:
Who is Participating?
 
sarabandeCommented:
you could try

if (File.Exists(@"D:\YOURFILEFOLDER\Test1.txt") ||
    File.Exists(@"D:\YOURFILEFOLDER\Test2.txt) ||  
    File.Exists(@"D:\YOURFILEFOLDER\Test3.txt) ||  
    File.Exists("D:\\YOURFILEFOLDER\\Test4.txt) ) 
{

Open in new window


note when using the @ you can use single backspace \ in path. when you omit the @ you need the \\ casue backspace is escape character.

if you need more help you should use the request attention button (below initial question) to reschedule your question and get more answers as i am not much experienced in c#.

Sara
0
 
sarabandeCommented:
from the ".csproj" in namespace it seems it is c# code.

Sara

0
 
srionline2k6Author Commented:
Where I need to look my question. I haven't got any replies yet Let mw know where can i get replies
0
 
sarabandeCommented:
for more info on File.Exists see http://msdn.microsoft.com/en-us/library/x23stk5t(v=vs.85).aspx

wildcards are not supported with that statement.

search with wildcards could be done like

string[] files = Directory.GetFiles(@"d:\yourfilefolder", "test*.txt"); 
if (files.Length > 0) 
{    
      //file exist 

Open in new window



Sara
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.