What's the sparse file attribute on NTFS partitions and how can one remove it?

Using Windows 7, Windows 8 and Windows 8.1.

  • Why would you want to remove it? – MJZ Dec 14 '12 at 2:14
  • 1
    @MJZ: I just want to know how can I achieve this. – m0nhawk Dec 14 '12 at 17:57

Nicole Hamilton provided the description of what sparse files are.
Let's learn it with an experiment.

Creating a Sparse File

Start a Command Prompt (cmd.exe) as Administrator.

  1. Creating large file:

    fsutil file createnew test.nul 1048576
  2. Check its size in Explorer:
    • Size: 1.00 MB (1,048,576 bytes)
    • Size on disk: 1.00 MB (1,048,576 bytes)
  3. Let's mark it sparse:

    fsutil sparse setflag test.nul
  4. Nothing changed so far, the both sizes are still 1.00 MB.
  5. Let's mark the entire byte range as sparse:

    fsutil sparse setrange test.nul 0 1048576
  6. Now the sizes changed dramatically:
    • Size: 1.00 MB (1,048,576 bytes)
    • Size on disk: 1.00 KB (1 024 bytes)
  7. You can query if the file is sparse or not with fsutil:

    fsutil sparse queryflag test.nul
    This file is set as sparse


    This file is NOT set as sparse

The value of Size on disk depends on the cluster size of the file system. The default cluster size on NTFS is 4 KB. The drive I used for testing was formatted with 1 KB cluster.

I used this article as the source.

Removing Sparse Attribute

The utility I used in the example does not provide a flag to remove sparse attribute.

The simplest way to do is to copy the file. The file will lose this special attribute if the application that copies it does not specially preserve the sparse attribute and sparse range.

You can use Far Manager to clear the sparse attribute. Navigate to the file and press Ctrl + A to open Attribute dialog. Clear Sparse check box. And click Set button. Attributes of test.nul file in Fra Manager

| improve this answer | |
  • NOT WORKING ! ... my file is 30G, I do NOT HAVE space to copy it, and far-manager do nothing when try to set that flag, I press ctrl+a again and attribute is STILL THERE :( – THESorcerer Apr 14 '15 at 16:00
  • @THESorcerer I didn't try to use Far Manager to set Sparse attribute, only to clear it. Does your file consists of zeroes only? If you look closely at fsutil command line, you'll see that Sparse attribute requires setrange to specify the range of bytes "compacted" by sparse attribute. Setting Sparse attribute doesn't automatically analyze the file structure to save disk space, you have to handle it. – Alexey Ivanov Apr 15 '15 at 8:08

A sparse file is one that has holes in it. Large sections of binary zeros aren't written to disk. Here's Microsoft's explanation from Sparse Files (Windows):

When sparse file functionality is enabled, the system does not allocate hard disk drive space to a file except in regions where it contains nonzero data. When a write operation is attempted where a large amount of the data in the buffer is zeros, the zeros are not written to the file. Instead, the file system creates an internal list containing the locations of the zeros in the file, and this list is consulted during all read operations. When a read operation is performed in areas of the file where zeros were located, the file system returns the appropriate number of zeros in the buffer allocated for the read operation. In this way, maintenance of the sparse file is transparent to all processes that access it, and is more efficient than compression for this particular scenario.

| improve this answer | |

This sparse attrib problem happens all the time with downloaded ISOs for me.

Put this in a batch file and drag-and-drop the target file onto it (with Windows Explorer). Et voilà.

fsutil sparse queryflag %1
fsutil sparse setflag %1 0
fsutil sparse queryflag %1

This does not work in Windows 7 and 8.x however (possibly Vista too) as setflag only accepts <filename> as a valid parameter and there is no corresponding clearflag command. It does however work in Windows 10.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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