Delete All Files in Folder

  • Thread starter Thread starter JasonP
  • Start date Start date
J

JasonP

I want to write a sub that will accept a folder parameter (string, as in:
"C:\Temp") and then delete all the files in that folder. Can anyone tell me
what a simple way to accomplish this is? I don't see an obvious method for
the Directory object; I assume I could get the file list for the Directory
and then explicitly delete each file, but is there a single-command method?

Thanks!
 
Awesome! Thanks.

Jeremy Cowles said:
method?

Dim di as New System.IO.DirectoryInfo("ZZ:\")

'// Delete the entire ZZ:\ volume, including all files & subdirs
di.Delete( True )

HTH

~
Jeremy
 
Hello,

JasonP said:
I want to write a sub that will accept a folder parameter (string, as in:
"C:\Temp") and then delete all the files in that folder. Can anyone tell me
what a simple way to accomplish this is? I don't see an obvious method for
the Directory object; I assume I could get the file list for the Directory
and then explicitly delete each file, but is there a single-command
method?

\\\
Dim s As String
For Each s In System.IO.Directory.GetFiles("C:\WINDOWS\TEMP")
System.IO.File.Delete(s)
Next s
///

-- or --

The BASIC way:

\\\
Kill("C:\WINDOWS\TEMP\*.*")
///

HTH,
Herfried K. Wagner
 
Back
Top