Re: Directory assistance
I am using this in an SSIS package and have been able to build a C# script to delete empty directories with the following:
public void Main()
{
try
{
ProcessDirectory(Dts.Variables["OuterDirectoryYYYYMMM"].Value.ToString());
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception ex)
{
Dts.TaskResult = (int)ScriptResults.Failure;
}
}
private static void ProcessDirectory(string startLocation)
{
foreach (var directory in Directory.GetDirectories(startLocation))
{
ProcessDirectory(directory);
if (Directory.GetFiles(directory).Length == 0 && Directory.GetDirectories(directory).Length == 0)
{
Directory.Delete(directory, false);
}
}
}