February 8, 2010 at 6:58 pm
hi all,
can some one help me to write a script task to loop through subfolders in a folder and delete any folders older than current date id. I am not a .NET programmer but a SQL developer
Say I have a datasource directory with the following subdirectories
20100204
20100205
20100208
20100209
I haev to delete all the folders from 20100204 to 20100208.
using For each file enumerator by checking traverse subfolder I do not think is a good option as it will traverse through all the files. Is there some other SSIS inbuilt task that i can use?
February 9, 2010 at 7:13 am
I would still consider trying the for each file enumerator along with a script task. I've deleted thousands of files in just a few minutes. The first time it runs it takes a bit longer than the rest but that's only because it had many more file to delete.
Dim daysToKeep As Int32
Dim fileToDelete As String
Dim compareDate As Date
Dim dateDiff As TimeSpan
compareDate = File.GetCreationTime(Dts.Variables("fileName").Value.ToString())
dateDiff = System.DateTime.Now.Subtract(compareDate)
daysToKeep = CInt(Dts.Variables("daysToKeep").Value.ToString())
fileToDelete = Dts.Variables("fileName").Value.ToString()
If dateDiff.Days > daysToKeep Then
File.Delete(fileToDelete)
End If
Dts.TaskResult = Dts.Results.Success
The above script only deletes files that are older than x number of days.
February 9, 2010 at 8:45 am
This seems to delete files, not folders ...
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
February 9, 2010 at 8:53 am
Phil Parkin (2/9/2010)
This seems to delete files, not folders ...
You're right. I misread the requirement. I think you could still do directory.delete(some sort of path))
February 9, 2010 at 3:05 pm
Thanks for the reply. I could not interprete the code very well.
All I am looking for is a .NEt code that would be something similar to
FOR EACH subfolder in the main Folder
GET Folder Name
say 20100204
IF(20100204 < 20100209) where 20100209 is the currentdateid and is stored in a variable
BEGin
DELETE Folder
END
ELSE
BEGIN
move the the contents of the folder with all files to a dataworkingdirectory
END
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply