473,699 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 88969
Awesome! Thanks.

"Jeremy Cowles" <jeremy.cowle s[nosp@m]asifl.com> wrote in message
news:KM******** ***********@twi ster.tampabay.r r.com...
"JasonP" <ja****@i.com > wrote in message
news:u$******** ********@tk2msf tngp13.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.Direc toryInfo("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.Direc tory.GetFiles(" C:\WINDOWS\TEMP ")
System.IO.File. Delete(s)
Next s
///

-- or --

The BASIC way:

\\\
Kill("C:\WINDOW S\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
15649
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. *FILE29*.TXT). I'm looking for a way to do this in either Visual Basic or C(++). Thanks!
2
28478
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 is the command for the same. thanks Regards umesh
5
13273
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
20069
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
2343
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 directory, at the time it is placed there, a row will be inserted into an RDBMS table which gives the filename, the location (could be on various servers), its time-to-live (like 2 days) and the datetime it was placed there, and probably a flag...
2
1802
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 any way to do this? Thanks
3
3906
by: Rajiv Das | last post by:
VS 2003, XP SP2 ------------------------------------------------------------ DirectoryInfo temporary = new DirectoryInfo( Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)); FileInfo files = temporary.GetFiles(); foreach(FileInfo fi in files) { Console.WriteLine(fi.FullName); }
9
8334
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) and two folders (Subfolder 1, Subfolder 2). .......I need to delete File1, File2, File3. Subfolder 1 contains FileA. .......Need to delete FileA. Subfolder 2 contains FileB, FileC, FileD.
1
1491
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> #include <windows.h> int main(int argc, const char * argv) { // Get a pointer to the file name/path const char * pFileToDelete = "c:\\Program Files\\myfile.txt";
1
3141
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 their paired "foreign" resx for that language only and installs those resource files in a subdirectory somewhere. I'm trying to create a setup project in visual studio 2008. Ive got my Application Folder set up with my executable. Im now...
0
8704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9192
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9054
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8940
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8895
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7781
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5879
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.