Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Let's say I have a Python program that opens a file and overwrites it with zeros, and I run it on a Windows 7 computer formatted in NTFS. If this is done on an HDD (not an SSD) will the file be overwritten in place on the disk, or will the changes be written in a new sector and the file link updated?

share|improve this question

1 Answer 1

Short answer:
Will the file be overwritten in place on the disk? Maybe.
For secure deletion of files, maybe, is not acceptable.

Longer answer:
I believe that depends on the flags used when opening the file and whether the file is compressed or encrypted. It seems many applications that look like they are just overwriting end up writing the new content to another location on the disk and leaving the original content still on the disk as well.

To check the before and after location of the file you can use the DiskView tool from http://technet.microsoft.com/en-au/sysinternals/bb896650.aspx

Are you looking for a tool that will write all free space with zeroes? There is a MS tool available for that but the way it works is that it creates new files filled with the same content (by default not zeros but compresses well anyway), and then deletes them all. See http://support.microsoft.com/kb/833138 for more info. It is also called "Virtual Disk Precompactor.ISO" and it is installed with Virtual PC or XP mode.

However this does create a short time when the disk is full and if the system is in use at the time it will spray new files all over the disk. I was thinking that if you could make use of the defragmentation APIs to move a zero filled file to all free space locations on the disk it would have less impact on the running system. But I've not seen any tools for doing this.

If you are looking for a tool to securely delete files there is one available from Microsoft on http://technet.microsoft.com/en-au/sysinternals/bb897443.aspx called sdelete which actually does some tricky things with the defragmentation API to actually erase sparse and compress files while just writing zeroes to those types of files will not write the zeroes to the same location as the old content due to the way ntfs works. The link for the sdelete program gives a description of this. Note that sdelete does not need to be installed as it is self contained.

share|improve this answer
    
No, it is a program that I wrote. It opens a file, fills everything with zeros, and then closes the file. –  chew socks Jul 1 '13 at 7:03
    
but why? are you trying to secure delete files? –  BeowulfNode42 Jul 1 '13 at 22:16
    
Yes, and without having to install a program. –  chew socks Jul 2 '13 at 3:26
    
The program is already finished, quick and easy. I just want to know if it works. –  chew socks Jul 2 '13 at 4:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.