469,926 Members | 1,950 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

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 83805
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撰寫於郵件新聞: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撰寫於郵件新聞: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.

Similar topics

3 posts views Thread by Krazitchek | last post: by
1 post views Thread by Keith Henderson | last post: by
3 posts views Thread by Rajiv Das | last post: by
1 post views Thread by cosmos22 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.