views:

203

answers:

3

Hi,

Is there a way to guarantee that a file on Windows (using the NTFS file system) will use contiguous sectors on the hard disk? In other words, the first chunk of the file will be stored in a certain sector, the second chunk of the file will be stored in the next sector, and so on.

I should add that I want to be able to create this file programmatically, so I'd rather not just ask the user to defrag their harddrive after creating this file. If there is a way to programmatically defrag just the file that I create, then that would be OK too.

Thanks,

Terry

A: 

I believe there's no way to achieve that. You can only defragment the file after it's been written.

gabr
+7  A: 

I would start here:

http://technet.microsoft.com/en-us/sysinternals/bb897428.aspx

and follow Mark's documentation of the defrag stuff:

http://technet.microsoft.com/en-us/sysinternals/bb897427.aspx

Will Dean
+1  A: 

I know of no such guarantees.

But also keep in mind that NTFS "files" are comprised of multiple data streams. So you are actually looking for a way to guarantee that a stream is contiguous.

Frank Krueger