Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 SSIS and Import/Export (2012)
 Need Urgent Help in SSIS

Author  Topic 

tooba
Posting Yak Master

224 Posts

Posted - 2013-10-15 : 16:59:43
Hi Guys,

Need help. My question is how i can delete few files if file name start with CUSTOME_FILE_........ from the directory. I am using SSIS and I know I can use FILE SYSTEM TASK to delete files from folders and schedule that SSIS Package, but I don't know how i can use like statement to delete few files.

Any help would be great appreciated.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-16 : 02:48:53
You need to use a For Each Loop to iterate through files
Inside Loop, Add a script task where you pass filename as a parameter and inside use string pattern comparison functions to check for the pattern inside file. Based on that return a boolean result (1 or 0). Add a file system task after that to delete the file. In precendence constraint from script task to File System Task use Expression and Constraint option and set expression as
@BooleanVariable == True

See below for similar logic I used inside script task to do pattern check based on date

http://visakhm.blogspot.in/2012/05/package-to-implement-daily-processing.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

tooba
Posting Yak Master

224 Posts

Posted - 2013-10-17 : 00:13:10
Thank You for your reply....I may need your help in Script Task.
In your E.g you are saying if date is greater then 0, How I can use this logic in Script task to find out Filename like '%Custom_File%,

I want to delete only those file where file name like '%Custom_File%'

Thanks for your help in advance.....
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-17 : 04:31:41
quote:
Originally posted by tooba

Thank You for your reply....I may need your help in Script Task.
In your E.g you are saying if date is greater then 0, How I can use this logic in Script task to find out Filename like '%Custom_File%,

I want to delete only those file where file name like '%Custom_File%'

Thanks for your help in advance.....


you can use a logic like

Dts.Variables("IsCustomFile").Value=IIF(Instr(Dts.variable("FileName").value,"Custom_Value")>0,True,False)

then use in precedence constraint a logic like

@IsCustomFile == True

I assume your FileName is stored in variable called FileName and boolean variable IsCustomFile is used to store the result
------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -