public void Main()
{
try
{
// Check the files on the folder. Delete any daily files greater than 10 days old.
string filePath = Dts.Variables["User::DestinationFolder"].Value.ToString();
int currentDay = DateTime.Now.DayOfYear;
int fileCreateDay;
DirectoryInfo info = new DirectoryInfo(filePath);
FileInfo[] files = info.GetFiles();
foreach (FileInfo file in files)
{
fileCreateDay = file.CreationTime.DayOfYear;
if ((currentDay - fileCreateDay) > 10)
{
try
{
//MessageBox.Show("greater than 5 days: " + file.FullName);
File.Delete(file.FullName);
}
catch
{
Dts.Variables["User::WarningMessage"].Value = "Point Daily: failed trying to delete old files.";
Dts.Variables["User::WarningOccurred"].Value = true;
Dts.TaskResult = (int)ScriptResults.Failure;
}
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
catch
{
Dts.Variables["User::WarningMessage"].Value = "Point Daily: error in Delete Old Files section";
Dts.Variables["User::WarningOccurred"].Value = true;
Dts.TaskResult = (int)ScriptResults.Failure;
}
}