By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,301 Members | 3,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,301 IT Pros & Developers. It's quick & easy.

How to delete all files under a folder

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
ad

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

"Greg Young" <dr*******************@hotmail.com撰寫於郵件新聞: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

P: n/a
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撰寫於郵件新聞: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 discussion thread is closed

Replies have been disabled for this discussion.