473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Delete All Files in Folder

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!
Nov 19 '05 #1
2 88866
Awesome! Thanks.

"Jeremy Cowles" <jeremy.cowles[nosp@m]asifl.com> wrote in message
news:KM*******************@twister.tampabay.rr.com ...
"JasonP" <ja****@i.com> wrote in message
news:u$****************@tk2msftngp13.phx.gbl...
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

Nov 19 '05 #2
Hello,

"JasonP" <ja****@i.com> 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
Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Ben | last post by:
Greetings, I am looking for a way to search for and delete files based on a pattern mask. For example, the search method would find all files matching a certain pattern containing wildcards (e.g....
2
by: U C | last post by:
Hi, Can i delete files in cdump folder. Whats the basic use of having files in cdump folder. Is there any need to take backup when deleting the same. I am having solaris if we can delet then what...
5
by: Raj | last post by:
Hi all, Can anyone help me with a script which would delete files or move them to a different folder at some scheduled time..! Please.....!!! Thanks in advance...
3
by: Krazitchek | last post by:
Hi, how do i do to delete files with a specific extension (like *.lnk). I try File.Delete(@"e:\test\\*.lnk) but it does not work, not the good way i guess... Help please, thanks.
1
by: Keith Henderson | last post by:
It seems that I will soon have to write a windows service (or if there's something more appripriate?) that will delete files off of a hard drive. Here's an example, a file will be placed in a...
2
by: Fei Li | last post by:
Hi, I tried to delete a folder from an installation project. It was not allowed because it was not empty. I tried to remove all files in it and it took years to delete all files. Is there...
3
by: Rajiv Das | last post by:
VS 2003, XP SP2 ------------------------------------------------------------ DirectoryInfo temporary = new DirectoryInfo( Environment.GetFolderPath(Environment.SpecialFolder.InternetCache));...
9
by: Paul | last post by:
I'm trying to make get my app to delete all the files in a specified folder and all the files within the folders of the specified folder. e.g. Folder 1 contains three files (File1, File2, File3)...
1
by: cosmos22 | last post by:
Hello, I have recently been able to delete files using this code(With the aid of others from the forum) And I was wondering how you can change this, to suit deleting a folder #include <iostream>...
1
by: Claire | last post by:
Ive written a small string resource building utility that I send out to our translators. I have a setup project for each language we support, which picks out a group of 12 english resx files plus...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.