Method to check if files exist

  • Good morning,

    I'm looking for a good method to check if 4-.txt files exist in a folder. If they do not, I will send an email using the mail task.

    Anyhow, I have seen many ideas but they all seem to be checking for the existence of a single file, not 4.

    Thanks

  • mbrady5 (10/31/2016)


    Good morning,

    I'm looking for a good method to check if 4-.txt files exist in a folder. If they do not, I will send an email using the mail task.

    Anyhow, I have seen many ideas but they all seem to be checking for the existence of a single file, not 4.

    Thanks

    Add a script task, with a Read/Write Boolean variable FilesExist.

    In your script task, set the value of FilesExist to true/false using the C# File.Exists method.

    Add an appropriate precedence constraint from your script task to your e-mail task.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • If you have xp_cmdshell enabled, it may be simpler to run a dir command and put the results into a staging table. You can then count the number of files and act accordingly. I recommend you use sp_send_dbmail from the database engine instead of the SSIS incarnation.

    John

  • John Mitchell-245523 (10/31/2016)


    If you have xp_cmdshell enabled, it may be simpler to run a dir command and put the results into a staging table. You can then count the number of files and act accordingly. I recommend you use sp_send_dbmail from the database engine instead of the SSIS incarnation.

    John

    I agree with the sp_send_dbmail comment, but not the 'may be simpler' bit.

    My suggestion requires 5 lines of code, no trips to the database and no shelling out to DOS 🙂

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • Yes, I did say "it may". It depends what you're familiar with and what the wider requirement is. I'm more comfortable with a single DOS command and the rest in T-SQL than writing in C~ or VB.Net or whatever. You may also find that you need the file names in the database, anyway. And since the database is going to be called into play (potentially) for sending e-mails as well, why not put it all in a stored procedure?

    John

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply