473,325 Members | 2,442 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,325 software developers and data experts.

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 84054
Try Directory.Delete 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.tcc.edu.twwrote in message
news:ef**************@TK2MSFTNGP04.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:e P**************@TK2MSFTNGP02.phx.gbl...
Try Directory.Delete
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.tcc.edu.twwrote in message
news:ef**************@TK2MSFTNGP04.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.GetFiles(@"C:\temp");
foreach (string file in files)
File.Delete(file);

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:e P**************@TK2MSFTNGP02.phx.gbl...
Try Directory.Delete
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.tcc.edu.twwrote in message
news:ef**************@TK2MSFTNGP04.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
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.