Solved

c# delete all files in a directory

Posted on 2011-03-02
4
664 Views
Last Modified: 2013-11-10
Seeing if someone has a function that takes a directory path as a variable.
Then code deletes all files in that particular directory.  
0
Comment
Question by:carsRST
  • 2
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
gdupadhyay earned 500 total points
ID: 35021948
You can do by following any one below:
using System.IO;

string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
foreach (string filePath in filePaths)
  File.Delete(filePath);

or

Array.ForEach(Directory.GetFiles(@"c:\MyDir\"),
             delegate(string path) { File.Delete(path); });

Open in new window

0
 
LVL 9

Expert Comment

by:gdupadhyay
ID: 35021960
0
 
LVL 16

Author Comment

by:carsRST
ID: 35022069
Thanks - I'll give it a try...
0
 
LVL 16

Author Closing Comment

by:carsRST
ID: 35022134
Bless your heart.

Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now