2

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

3 Answers 3

7

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.

2
For Each file As String In Directory.GetFiles(strDirectory)
    File.Delete(file)
Next
2
  • Ooh. You beat me by 13 seconds. :-)
    – Sir Wobin
    Nov 19, 2010 at 20:31
  • 1
    Also, I wrote it in VB.NET, which (according to the question tags) is the language the OP is using. :P
    – cdhowie
    Nov 19, 2010 at 20:32
1
using System.IO;

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.