473,765 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to delete all files under a folder

ad
Hi,
How can I delete all files in a folder by C#
for example, I want to delete all files under c:\Test
Aug 22 '06 #1
3 84080
Try Directory.Delet e http://msdn2.microsoft.com/en-us/library/fxeahc5f.aspx

Remember to pass true to tell it to recurse subdirectories etc.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"ad" <fl****@wfes.tc c.edu.twwrote in message
news:ef******** ******@TK2MSFTN GP04.phx.gbl...
Hi,
How can I delete all files in a folder by C#
for example, I want to delete all files under c:\Test

Aug 22 '06 #2
ad

Thanks,
But I want delete all files in a folder by C#, but remain the folder.

"Greg Young" <dr************ *******@hotmail .com¼¶¼g©ó¶l¥ó· s»D:eP********* *****@TK2MSFTNG P02.phx.gbl...
Try Directory.Delet e
http://msdn2.microsoft.com/en-us/library/fxeahc5f.aspx

Remember to pass true to tell it to recurse subdirectories etc.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"ad" <fl****@wfes.tc c.edu.twwrote in message
news:ef******** ******@TK2MSFTN GP04.phx.gbl...
>Hi,
How can I delete all files in a folder by C#
for example, I want to delete all files under c:\Test


Aug 23 '06 #3
Hi ad,
Could you just iterate over the files?
string[] files = Directory.GetFi les(@"C:\temp") ;
foreach (string file in files)
File.Delete(fil e);

John

ad wrote:
Thanks,
But I want delete all files in a folder by C#, but remain the folder.

"Greg Young" <dr************ *******@hotmail .com¼¶¼g©ó¶l¥ó· s»D:eP********* *****@TK2MSFTNG P02.phx.gbl...
Try Directory.Delet e
http://msdn2.microsoft.com/en-us/library/fxeahc5f.aspx

Remember to pass true to tell it to recurse subdirectories etc.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"ad" <fl****@wfes.tc c.edu.twwrote in message
news:ef******** ******@TK2MSFTN GP04.phx.gbl...
Hi,
How can I delete all files in a folder by C#
for example, I want to delete all files under c:\Test
Aug 23 '06 #4

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

Similar topics

11
15656
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
28505
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
13275
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
20084
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
2345
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
1807
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
3908
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
8336
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
1494
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
3144
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
9399
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
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
10007
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
9957
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
9835
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
8832
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...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.