Looping through destination folder and checking if the file exist

Hey guys, I just have a question? How to design ta SSIS package which loops through DESTINATION folder files and checks whether that file is there in the SOURCE or not.

If the file exists then I have to check the modified date on DESTINATION file if it is greater than 1 day delete that file. If the modified date is less than that SOURCE file then I have to copy that file to DESTINATION<o:p></o:p>

 <o:p></o:p>

If there are files which exists in SOURCE and not in DESTINATION, then how shall we copy all the files to the DESTINATION that are created on the day of execution of package.<o:p></o:p>

May 29th, 2015 1:04pm

It seems like using robocopy tool here is more appropriate

Otherwise use the ForEach Loop set to iterate on files with a mask like *.csv

Example https://www.simple-talk.com/sql/ssis/ssis-basics-introducing-the-foreach-loop-container/

To get the file properties you need to code some C# or VB http://microsoft-ssis.blogspot.ca/2011/03/get-file-properties-with-ssis.html

To only copy the files day old you can have conditional processing using the precedence constraints

Free Windows Admin Tool Kit Click here and download it now
May 29th, 2015 1:38pm

Also, this can be done using a Script task/ FileSystem task/ Foreach Loop Container to check if the file exists or not using

string[] files = System.IO.Directory.GetFiles

(Dts.Variables["User::DestinationFolderPath"].Value.ToString(),

"SourceFileName", System.IO.SearchOption.TopDirectoryOnly);

If the file exists, using Directory.GetLastWriteTime method to get the modified date on source and destination files and then compare the dates and then pass back values to Read/Write variables back to next task and then use Precedence Constraint to whether to copy/delete the file using File System task

May 29th, 2015 4:02pm

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

Other recent topics Other recent topics