PC Review


Reply
Thread Tools Rate Thread

Delete All Files in Folder

 
 
JasonP
Guest
Posts: n/a
 
      26th Aug 2003
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!


 
Reply With Quote
 
 
 
 
JasonP
Guest
Posts: n/a
 
      26th Aug 2003
Awesome! Thanks.

"Jeremy Cowles" <jeremy.cowles[nosp@m]asifl.com> wrote in message
news:KMK2b.2209$(E-Mail Removed)...
> "JasonP" <(E-Mail Removed)> wrote in message
> news:u$9uWN%(E-Mail Removed)...
> > 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 di as New System.IO.DirectoryInfo("ZZ:\")
>
> '// Delete the entire ZZ:\ volume, including all files & subdirs
> di.Delete( True )
>
> HTH
>
> ~
> Jeremy
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      26th Aug 2003
Hello,

"JasonP" <(E-Mail Removed)> schrieb:
> 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
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete all files except one folder liu Windows XP General 21 21st Jun 2010 11:48 PM
How to delete all files under a folder ad Microsoft C# .NET 3 23rd Aug 2006 12:09 PM
Can't delete a folder and files Andy Windows XP General 6 30th Oct 2005 12:29 PM
Cannot delete files from program files folder Katie Windows XP Performance 0 21st Dec 2003 04:52 PM
can't delete folder or files Tena Heffernan Microsoft Windows 2000 Security 1 23rd Oct 2003 02:12 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:54 PM.