Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SSIS File System Task - delete directory issue


SSIS File System Task - delete directory issue

Author
Message
theboyholty
theboyholty
SSC-Enthusiastic
SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)

Group: General Forum Members
Points: 128 Visits: 123
I'm creating a package which deletes folders when they reach a certain age. It works fine as long as the folder exists.

If I try to delete a folder that doesn't exist, I get an error and the package fails.

What I want is for the package to continue to run if there's nothing to delete.

I've changed FailPackageOnFailure and FailParentOnFailure but these don't make a difference.

Does anyone know how I can do this?
aaron.reese
aaron.reese
Mr or Mrs. 500
Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)

Group: General Forum Members
Points: 589 Visits: 898
Its late on Friday at the end of a hard week...

Setting the Fail values is not going to help in this instance because the package is crashing rather than failing.

How are you verifying that the folder exists?
theboyholty
theboyholty
SSC-Enthusiastic
SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)

Group: General Forum Members
Points: 128 Visits: 123
I'm not verifying it exists at all. I'm just deleting it, and when it doesn't exists, then I have a problem. I suppose that's my question now then isn't it, how do I verify that the folder exists?
aaron.reese
aaron.reese
Mr or Mrs. 500
Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)Mr or Mrs. 500 (589 reputation)

Group: General Forum Members
Points: 589 Visits: 898
yup. You might need to use a script component or WMI. Here are a couple of links


http://www.bidn.com/blogs/mikedavis/ssis/157/ssis-wmi-event-watcher-check-file-exist-creation


http://www.bidn.com/blogs/DevinKnight/ssis/76/does-file-exist-check-in-ssis
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)SSCrazy Eights (8.3K reputation)

Group: General Forum Members
Points: 8310 Visits: 19457
aaron.reese (3/24/2014)
yup. You might need to use a script component or WMI. Here are a couple of links


http://www.bidn.com/blogs/mikedavis/ssis/157/ssis-wmi-event-watcher-check-file-exist-creation


http://www.bidn.com/blogs/DevinKnight/ssis/76/does-file-exist-check-in-ssis


Use a Script Task, not a Script Component.

Here's a C# snippet that you should be able to adapt:

string fldr = @"C:\Temp";      
// If directory does not exist, don't even try
if (Directory.Exists(fldr))
{
Directory.Delete(fldr);
}




Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
theboyholty
theboyholty
SSC-Enthusiastic
SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)SSC-Enthusiastic (128 reputation)

Group: General Forum Members
Points: 128 Visits: 123
I used your code and adapted it as there was an issue where the directory couldn't be deleted if it contained files (or it could have been to do with the permissions level - I'm not sure).
This is what I used in the end.


string folder = Dts.Variables["FolderToDelete"].Value.ToString();
if (Directory.Exists(folder))
{

string[] files = Directory.GetFiles(folder);
string[] dirs = Directory.GetDirectories(folder);

//delete files from folder
foreach (string file in files)
{
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}

//delete folder
Directory.Delete(folder, false);
}


Thanks for your help. I couldn't have managed without it.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search