user455100
user455100

Reputation: 151

SSIS: How to programmatically delete all files in a given folder?

I would like do this in a script task. For example i would like to be able to do something like this:

For each file as file in strDirectory
 file.delete
next file

Upvotes: 2

Views: 6999

Answers (3)

Jeff Hornby
Jeff Hornby

Reputation: 13640

Why do this in a script task? The File System task has the ability to Delete Directory Content without having to program a Script Task.

Upvotes: 7

Sir Wobin
Sir Wobin

Reputation: 1140

using System.IO;

foreach (FileInfo f in new DirectoryInfo("c:\dir").GetFiles())
     f.Delete();

Upvotes: 1

cdhowie
cdhowie

Reputation: 168988

For Each file As String In Directory.GetFiles(strDirectory)
    File.Delete(file)
Next

Upvotes: 2

Related Questions