Home arrow Delphi-Kylix arrow Secure File Deletion in Delphi

Secure File Deletion in Delphi

Everybody knows that simply deleting a file from a hard disk doesn't truly make the file impossible to recover. Often, this is a good thing, but sometimes you want a file to be thoroughly deleted. Keep reading to find out how to accomplish this.

Author Info:
By: Jacques Noah
Rating: 4 stars4 stars4 stars4 stars4 stars / 19
November 14, 2005
  1. · Secure File Deletion in Delphi
  2. · Building the GUI
  3. · The code
  4. · The rest of the code

print this article

Secure File Deletion in Delphi
(Page 1 of 4 )

A downloadable zip of the source code is available here.


While cleaning my hard disk, I started to wonder what happens to files when they are deleted. We hear all the time that when we delete files, they do not really disappear and can be recovered. To understand what happens to the files, we need to know what happens when files are created. When a new file is created, Windows allocates a space or place on the hard disk that uniquely identifies this file. Windows does not really keep taps on what a file contains; the only things it knows about a file is where it is located, its size and perhaps its name.

Now, when you delete a file (empty the recycling bin), all that happens is that Windows puts up a flag indicating that the space that used to belong to the deleted file is now available for re-allocation. At this point the file can still be recovered, but if you then create a new file or do anything that requires the OS to write something to the hard disk (such as restarting your computer), then the file will not be recoverable.

So, to completely delete a file, Windows overwrites it over and over. The more it overwrites, the more difficult it becomes to recover a file, and thus the more secure the deletion of the file. The US department of Defense has created a standard (considered to be the safest) called ĎDOD 5220.22-M.' It encourages rewriting file contents up to 20 times to make it completely unrecoverable, even with the most sophisticated recovery software known today. What we will do in this tutorial is devise an algorithm that will do the following:

  • Open and overwrite the file contents.

  • Rename and delete the file.

Itís fairly simple, but sufficient for anyone who wants to permanently delete their "secret" files. With this algorithm, even if someone manages to undo the renaming of the file or is able to undelete the file, the file would have been overwritten so many times that it will not be possible to recover its contents.

What you need

Iím using Delphi 7 Ent, but any version will do.

blog comments powered by Disqus

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials