check if file exists inside foreach container?
Hi All,
I have a foreach container that checks a folder C:\FTP for an Excel file named Fast_<date>.xls, imports the data, and copies the file to C:\Archive.
I need to add a step that checks C:\Archive for a file with the same name as the file in C:\FTP before the import step. If the file is already present in C:\Archive, the package should fail. If it isn't, then it should continue normally.
I found a promising-looking link in a previous post, but the referenced page no longer exists (below). I have never used a script task, and I will have a different file name each time, so I am a little confused.
If someone's feeling benevolent, suggestions would be very much appreciated!!
Thanks in advance!
broken link:
http://agilebi.com/cs/blogs/jwelch/archive/2007/10/31/checking-for-the-existence-of-a-file.aspx
November 18th, 2010 6:22pm
Why would you need a Script task to simply copy files from source to destination location?? Simply use a FileSystem task, set the SourceConnection and DestinationConnection, set Operation to "Copy File" and set the "OverwriteDestination" property
to "False". If the file with the same name already exists in the destination folder, the copy operation will fail .
Hope this helps.
Cheers!!
Muqadder.
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2010 6:28pm
Will that ensure that any downstream step does not execute? The idea is to keep from importing duplicate files. Thanks!!
November 18th, 2010 6:42pm
By default the "Overwrite Destination" property of File System Task is false and if the file already exists then the task will fail. Use a precedence constraint (Green Arrow) to connect to any subsequent task so that execution stops if the File System
task fails. Use the Red arrow from the File System Task to log (if required) into a table (date,message) with a message that "File already exists" and date as current date.
Nitesh Rai- Please mark the post as answered if it answers your question
Free Windows Admin Tool Kit Click here and download it now
November 18th, 2010 9:34pm
If you want a sample Script to work from, try
here.
If you want a easy to use task, try
here.
Talk to me now on
November 19th, 2010 11:32am
By default the "Overwrite Destination" property of File System Task is false and if the file already exists then the task will fail. Use a precedence constraint (Green Arrow) to connect to any subsequent task so that execution stops if the File
System task fails. Use the Red arrow from the File System Task to log (if required) into a table (date,message) with a message that "File already exists" and date as current date.
Nitesh Rai- Please mark the post as answered if it answers your question
A Precedence constraint in this case won't be necessary. If the OverwriteDestination property is set to False and the file already exists, the FileSystem task will fail, in turn failing the package (unless you have set the FailPackageOnFailure property of FileSystem
task to False). Hence, any subsequent tasks will not execute and the package will stop execution right at the FileSystem task itself, reporting a failure.
Hope this helps.
Cheers!!
Muqadder.
Free Windows Admin Tool Kit Click here and download it now
November 19th, 2010 12:47pm
The correct link for that article is
http://agilebi.com/jwelch/2007/11/01/checking-for-the-existence-of-a-file/.
I moved to a new hosting provider and platform earlier this year - sorry about that.John Welch | www.varigence.com | www.agilebi.com | ssisUnit.codeplex.com
November 20th, 2010 11:10pm