October 8, 2008 at 11:43 am
Hi...I want to build an SSIS package that deletes the log files whose names are like Package20081002.txt. The names of the logfiles ends with the current date. I want to maintain only 1 week log files and delete the older files. any help would be appreciated...Thank You
October 8, 2008 at 4:58 pm
You could use a ForEach container to iterate through all of the files with a pattern: Package*.txt
In the container put a Script task. Test the file name pattern for the date stamp. If it is old enough, set a flag to delete the file. Then use a File Sytem task to delete the file if the delete file flag is set (put the test in the precedence constraint.
Here is a means to delete a group of files:
http://blogs.conchango.com/jamiethomson/archive/2008/04/17/ssis-deleting-a-group-of-files.aspx
Russel Loski, MCSE Business Intelligence, Data Platform
October 8, 2008 at 5:00 pm
Thanks a lot....Let me try this....
October 8, 2008 at 5:21 pm
Uh, you don't need a script task for this. This is an extremely simple operation to do. Use the ForEach Loop Container and place a File System Task inside of it. Configure the File System Task to delete the file from a variable. Use the combination of the loop container, the variable, and an expression (to get date) to delete the files.
October 8, 2008 at 5:39 pm
I think I see where you are going with this. Very clever.
In the Precedence constraint you need an expression that parses the last 8 character into a date string and compare it against the current date. If that date piece is before one week ago, then allow the file task to delete otherwise go to the next file.
You wouldn't need the Script task.
Russel Loski, MCSE Business Intelligence, Data Platform
October 8, 2008 at 6:17 pm
yeah....I tried using file system task and for each loop container....but it deletes all the files in it....may be I will try ur way....Thanks for the correction....
October 9, 2008 at 10:30 am
Hi...I am having problems with the variable expression...I did 'nt understand what expression to put in the variable....the file name is like pakcage20080105.txt......could you please explain me what value i should put in the expression...
October 9, 2008 at 12:40 pm
I'm trying to make this work with just an expression and it is complicated. I would go back to using a script component to strip out the date portion of the file name.
Russel Loski, MCSE Business Intelligence, Data Platform
October 9, 2008 at 1:02 pm
Hope below link will help
http://rafael-salas.blogspot.com/2007/02/ssis-loop-through-files-in-date-range.html
October 9, 2008 at 1:59 pm
yeah....It should work...Thank u very much...
July 30, 2013 at 11:36 am
I need to delete files that are older than 5 business days. Can I do it using a foreach container and a file system task or do I need to use a script component?
July 30, 2013 at 11:47 am
You are going to need to use a script task, if only to get the date last modified.
Russel Loski, MCSE Business Intelligence, Data Platform
July 30, 2013 at 12:06 pm
Ok. That's what I was thinking. I'll use a Script Component to get the max date. And then use the for each container and file task to loop thru the files and delete them.
Thanks!
July 30, 2013 at 12:13 pm
You could also delete the files from withing the script component.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
July 30, 2013 at 12:40 pm
I was thinking that as a backup. I haven't worked with the foreach loop container so wanted to give that a try. Thanks Alvin!
I'm following this article: http://consultingblogs.emc.com/jamiethomson/archive/2008/04/17/ssis-deleting-a-group-of-files.aspx. I don't understand why in the Variable Mappings tab I have to create a variable by the name of FileName. Are all of the file names stored in that variable?
Viewing 15 posts - 1 through 15 (of 20 total)
You must be logged in to reply to this topic. Login to reply