Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SSIS File System Task - delete directory issue Expand / Collapse
Author
Message
Posted Friday, March 21, 2014 9:54 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, October 30, 2014 3:37 AM
Points: 112, Visits: 89
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?
Post #1553568
Posted Friday, March 21, 2014 10:24 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 9:41 AM
Points: 434, Visits: 664
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?


Post #1553596
Posted Monday, March 24, 2014 5:14 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, October 30, 2014 3:37 AM
Points: 112, Visits: 89
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?
Post #1553962
Posted Monday, March 24, 2014 11:00 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 9:41 AM
Points: 434, Visits: 664
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
Post #1554141
Posted Tuesday, March 25, 2014 1:09 AM This worked for the OP Answer marked as solution


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 11:02 PM
Points: 5,259, Visits: 12,193
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.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #1554295
Posted Tuesday, March 25, 2014 6:45 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, October 30, 2014 3:37 AM
Points: 112, Visits: 89
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.
Post #1554428
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse