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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 SSIS and Import/Export (2012)
 Need Urgent Help in SSIS
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tooba
Posting Yak Master

224 Posts

Posted - 10/15/2013 :  16:59:43  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 10/16/2013 :  02:48:53  Show Profile  Reply with Quote
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 - 10/17/2013 :  00:13:10  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 10/17/2013 :  04:31:41  Show Profile  Reply with Quote
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

Edited by - visakh16 on 10/17/2013 04:32:56
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000