×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

delete all files in hard disk

delete all files in hard disk

delete all files in hard disk

(OP)
can any one give me code to delete all files in hard disk by c#

RE: delete all files in hard disk

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

RE: delete all files in hard disk

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.

RE: delete all files in hard disk

(OP)
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

RE: delete all files in hard disk

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);

RE: delete all files in hard disk

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);

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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! Already a Member? Login


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