Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This is easily the most helpful website I've ever used, and this is the best forum with the quickest response time bar none...."

Geography

Where in the world do Tek-Tips members come from?
ahm123 (Programmer)
15 May 12 5:14
can any one give me code to delete all files in hard disk by c#
NESWalt (Programmer)
15 May 12 10:23
Are you trying to delete all files in a directory or the entire disk? What are you really trying to do?

Walt
IT Consulting for Robert Half
http://roberthalftechnology.com

xwb (Programmer)
15 May 12 11:55
Is that a partitioned disk? Do you want to wipe all the files in a partition or wipe all the partitions?

There are system commands like format and fdisk which do that.
ahm123 (Programmer)
16 May 12 2:52
I want to delete all file in directory meaning if i have drive D can i try to delete all files found in this drive by c# code
please help me
ralphtrent (Programmer)
16 May 12 10:06
A drive and directory are two different things. A drive is all folders and files where a directory is a subset of the drive. You need to be VERY clear and understand what it is you want to do. formatting the drive will remove ALL files and folders on the drive.

Here is a wiki link to what format is

With that said, here is some code TO GET YOUR STARTEDs. I have not tested this code, since I do not have any drives that I want to format so you will need to review it and test it and make any changes neccessary, like throwing in a Warning to the user explaining to them that this will do:

CODE

static void FormatDrive( System.IO.DriveInfo drive) { if (drive.IsReady) { System.Diagnostics.Process format = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo psiFormat = new System.Diagnostics.ProcessStartInfo(); psiFormat.FileName = "format.exe"; psiFormat.WorkingDirectory = "%windir%\\systm32"; psiFormat.Arguments = drive.Name; format.StartInfo = psiFormat; format.Start(); psiFormat = null; format = null; } }

if you want to just delete files and folders in a directory do this

CODE

new System.IO.DirectoryInfo("c:\\temp\\").Delete(true);
ralphtrent (Programmer)
16 May 12 10:06
A drive and directory are two different things. A drive is all folders and files where a directory is a subset of the drive. You need to be VERY clear and understand what it is you want to do. formatting the drive will remove ALL files and folders on the drive.

Here is a wiki link to what format is

With that said, here is some code TO GET YOUR STARTEDs. I have not tested this code, since I do not have any drives that I want to format so you will need to review it and test it and make any changes neccessary, like throwing in a Warning to the user explaining to them that this will do:

CODE

static void FormatDrive( System.IO.DriveInfo drive) { if (drive.IsReady) { System.Diagnostics.Process format = new System.Diagnostics.Process(); System.Diagnostics.ProcessStartInfo psiFormat = new System.Diagnostics.ProcessStartInfo(); psiFormat.FileName = "format.exe"; psiFormat.WorkingDirectory = "%windir%\\systm32"; psiFormat.Arguments = drive.Name; format.StartInfo = psiFormat; format.Start(); psiFormat = null; format = null; } }

if you want to just delete files and folders in a directory do this

CODE

new System.IO.DirectoryInfo("c:\\temp\\").Delete(true);

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close