In the same vein as Quickly create a large file on a Linux system, I'd like to quickly create a large file on a Windows system. By large I'm thinking 5 GB. The content doesn't matter. A built-in command or short batch file would be preferable, but I'll accept an application if there are no other easy ways.
24 Answers
fsutil file createnew <filename> <length>
where <length>
is in bytes.
For example, to create a 1MB (Windows MB or MiB) file named 'test', this code can be used.
fsutil file createnew test 1048576
fsutil
requires administrative privileges though.

- 3,049
- 3
- 23
- 34

- 28,540
- 12
- 67
- 94
-
6@ZXX +1 For my purposes I merely needed the file system to see the space as unavailable, but your information is helpful if someone else needs this. – Leigh Riffel Dec 22 '10 at 13:50
-
23fsutil file createnew does _not_ create a sparse file. – Per Mildner Jun 30 '13 at 17:58
-
10"fsutil sparse setflag temp.txt" sets the sparse flag, making it a sparse file. "fsutil sparse setrange temp.txt 0 1024" sets the range of sparseness :) – Coldblackice May 10 '14 at 21:53
-
is there a way without administrator privileges? – wizlog Aug 07 '17 at 16:53
-
3@ZXX `fsutil file createnew` does NOT create sparse files: `c:\>fsutil file createnew test.txt 0x100000` `File c:\test.txt is created` `c:\>fsutil sparse queryflag test.txt` `This file is NOT set as sparse` – ivan_pozdeev Oct 20 '17 at 06:29
-
I've created a Windows Batch File tool for creating large files based on this method. Find it here: https://gist.github.com/Richienb/0393f04b10ba9c2395cf3dbe911e660d – Richie Bendall Jun 10 '18 at 02:07
-
3This might not technically be a sparse file, but creating a 500GB file takes less than a second (even on a somewhat faulty hard disk). If you want to actually trigger 500GB of disk IO (like I do), this command isn't it. – Simon Kissane Oct 05 '18 at 07:43
-
Even “FSUTIL sparse setflag” does not make a file actually sparse, it just flags it so that future writes will be recorded as sparse, but it does not reduce its size even if it's totally filled with zeroes. The only tool I found which can turn a non-sparse file into a sparse file (and actually reduce its size, not just flag it) is SparseTest, a command line tool originally made for testing purposes, which is no longer officially available, so it's quite hard to get, but it works very well and is secure (checksum control). You can find it on Archive.org : tinyurl.com/MoonlighDemos20161012 – GabrielB Jul 15 '19 at 16:00
-
Note that a file extension is REQUIRED. Without it "Access Denied" error gets thrown.. – Ujjwal Singh Jul 04 '20 at 22:36
-
This command is magic ;-) Whilst it creates a non-sparse file (i.e. size on disk = size of file), it doesn't grow a virtual disk. My head is wobbling thinking about that! – Rob Nicholson Aug 06 '21 at 08:58
You can use the Sysinternals Contig tool. It has a -n
switch which creates a new file of a given size. Unlike fsutil
, it doesn't require administrative privileges.

- 344,408
- 85
- 689
- 683
-
2Wow! Very fast to download and to run. The line I used is m:\contig -n M:\SpaceBuffer.tmp 5368709120 – Leigh Riffel Jun 11 '09 at 19:52
-
6Just want to check if this is a sparse file or does the file actually have data in it? – slolife Jun 02 '11 at 17:35
-
2
-
-
1I'm confused here... if it is instantaneous, and it's not a sparse file, then how does it actually use up disk space? – Jason S Jan 04 '18 at 16:22
-
3@JasonS: `contig` effectively goes to the last byte and writes a single `0` there (just look with Process Monitor). Windows then fills the rest with zeroes. This is probably about as efficient as you can get with non-sparse files and creation of a file about 5 GiB in size only takes a few seconds even on my hard disk. I guess back then I've tried either on an SSD or with smaller files. But it is rather quick (and definitely faster than to write all bytes of the empty file by yourself. – Joey Jan 07 '18 at 10:43
I was searching for a way to generate large files with data, not just sparse file. Came across the below technique:
If you want to create a file with real data then you can use the below command line script.
echo "This is just a sample line appended to create a big file.. " > dummy.txt for /L %i in (1,1,14) do type dummy.txt >> dummy.txt
(Run the above two commands one after another or you can add them to a batch file.)
The above commands create a 1 MB file dummy.txt within few seconds...
-
6Extract from the link above: If you want to create a file with real data then you can use the below command line script. `echo "This is just a sample line appended to create a big file.. " > dummy.txt for /L %i in (1,1,14) do type dummy.txt >> dummy.txt` (Run the above two commands one after another or you can add them to a batch file.) The above commands create a 1 MB file dummy.txt within few seconds. – Tony Stark Aug 26 '14 at 09:08
-
Attention: You must copy the first line first, hit Enter and than copy the second line. I tried copying the whole script into my shell but then nothing happed. – Magiranu Nov 20 '17 at 10:20
Open up Windows Task Manager, find the biggest process you have running right click, and click on Create dump file
.
This will create a file relative to the size of the process in memory in your temporary folder.
You can easily create a file sized in gigabytes.

- 30,738
- 21
- 105
- 131

- 11,969
- 12
- 64
- 118
-
3nice solution! Helpful if you have a variety of applications running, to get different sizes – Don Cheadle May 12 '17 at 14:57
Check out RDFC http://www.bertel.de/software/rdfc/index-en.html
RDFC is probably not the fastest, but it does allocate data blocks. The absolutely fastest would have to use lower level API to just obtain cluster chains and put them into MFT without writing data.
Beware that there's no silver bullet here - if "creation" returns instantly that means you got a sparse file which just fakes a large file, but you won't get data blocks/chains till you write into it. If you just read is you'd get very fast zeros which could make you believe that your drive all of the sudden got blazingly fast :-)

- 30,738
- 21
- 105
- 131

- 4,684
- 27
- 35
-
This seems to be the best answer. FSUTIL creates a sparse file which is not a valid test scenario for many cases. Sysinternals contig never seems to work for me, when I use a command like "contig -n largefile.bin 6000000000 it creates a file 1.7GB in size...??? Thanks for RDFC because it worked perfectly the first try and writes at the max write speed of my ATA disk. – Syclone0044 Jun 18 '13 at 01:41
-
As it's been said above, FSUTIL “createnew” does NOT create sparse files, it just allocates (in the MFT) the requested space to the requested file, i.e. the full space. If you then check the file's properties, the allocated size (annoyingly named “size on disk” as it can be on any device that's not necessarily a “disk”) is similar or very close to the actual size. A real sparse file totally filled with zeroes would have a very small allocated size. The only tool I found which can turn a non-sparse file into a sparse file (and actually reduce its size, not just flag it) is SparseTest. – GabrielB Jul 15 '19 at 15:47
I needed a regular 10 GB file for testing, so I couldn't use fsutil
because it creates sparse files (thanks @ZXX).
@echo off
:: Create file with 2 bytes
echo.>file-big.txt
:: Expand to 1 KB
for /L %%i in (1, 1, 9) do type file-big.txt>>file-big.txt
:: Expand to 1 MB
for /L %%i in (1, 1, 10) do type file-big.txt>>file-big.txt
:: Expand to 1 GB
for /L %%i in (1, 1, 10) do type file-big.txt>>file-big.txt
:: Expand to 4 GB
del file-4gb.txt
for /L %%i in (1, 1, 4) do type file-big.txt>>file-4gb.txt
del file-big.txt
I wanted to create a 10 GB file, but for some reason it only showed up as 4 GB, so I wanted to be safe and stopped at 4 GB. If you really want to be sure your file will be handled properly by the operating system and other applications, stop expanding it at 1 GB.

- 6,716
- 8
- 36
- 53
-
You need to use a single percent character, not double. Also, you don't need the extra spaces in the parentheses. I'll edit that for you. – Samir Nov 02 '13 at 21:19
-
What operating system did you use here mate? The `rm` is a Unix/Linux command, while `del` is a DOS/Windows command?... – Samir Nov 02 '13 at 21:39
-
Is this supposed to be a batch file or are you supposed to issue these commands straight up in cmd? Single percent sign is used in cmd, like `%i` but in a batch file you use double percent sign, like `%%i`. – Samir Nov 02 '13 at 21:50
-
@Sammy: It starts with `@echo off`, so it's obviously a `.bat`. That's why it had double percent signs. – f.ardelian Nov 02 '13 at 21:52
-
Alright, then we might want to bring back the double percent sign. Why do you delete `file-4gb.txt` before you create it? Wouldn't that result in error? Did you actually meant to create `file-4gb.txt` on that line? Or rename the old `file-big.txt` file? This is unclear, even for a batch file. If you meant to rename it, then the command you were looking for is probably `ren`. Like `ren file-big.txt file-4gb.txt`. I think you confused that with `rm`. – Samir Nov 02 '13 at 22:01
-
The new edit will produce a new file for each loop, for 1 KB, 1 MB, 1 GB, and 4 GB. This gives you more options, i.e. you can choose what file size to work with. It will require a little over 5 GB of free disk space. To conserve space, you can simply work with one single file by renaming "file-big-1K.txt" et al to "file-big.txt". – Samir Nov 02 '13 at 22:57
-
How much RAM do you have? I'm thinking that this might have to do with a memory limitation. But you can use the RDFC tool linked to above to create a 10 GB file, you can use `rdfc newtestfile.dat 10 GB`. – Samir Nov 02 '13 at 23:21
Check the Windows Server 2003 Resource Kit Tools. There is a utility called Creatfil.
CREATFIL.EXE
-? : This message
-FileName -- name of the new file
-FileSize -- size of file in KBytes, default is 1024 KBytes
It is the similar to mkfile on Solaris.

- 1,213
- 1
- 15
- 27

- 52,691
- 28
- 123
- 168
-
2
-
you would only need the 1 exe from the resource kit, you don't have to have the whole thing on your production system. – Byron Whitlock Jun 11 '09 at 18:51
-
1I'll give it a try, but I'd rather not have the additional file dependency. – Leigh Riffel Jun 11 '09 at 19:30
-
The file isn't downloading correctly for me now, but I can't imagine it being faster than the Contig tool mentioned by Johannes Rossel. – Leigh Riffel Jun 11 '09 at 21:30
-
1Thanks! The downloaded package is rktools.exe and it's 11.7 MB and 18.2 MB when expanded. Oh, and that's **"creatfil.exe"** and not "createfil.exe". This file alone is 5.5 KB in size and that's all you really need. It took me less than 1 minute to generate a 1 GB file on a quad core 3.0 GHz Intel cpu. With the fsutil.exe tool as posted above, it only takes a fraction of a second to create it. So it's true, that tool creates sparse files. It's even bigger, it's 73,5 KB. This one is better for generating large files for testing purposes. – Samir Nov 02 '13 at 17:45
-
I tried Contig and it didn't even work. I might be using wrong syntax. But that just shows how Creatfil.exe is easier to use. Contig is packaged in a 102 KB Zip file. It's 203 KB when expanded. – Samir Nov 02 '13 at 17:53
-
So I was using the wrong syntax with Contig. I got it now. It created a 1 GB file instantaneously. So it does seem to be faster than Creatfil.exe. But I doubt that it actually fills the file with data. It seems too good to be true. But I'd say both Contig, Creatfil, or even RDFC are all good options. Not so much the Fsutil tool. It requires using additional commands to fill the file with real data. – Samir Nov 02 '13 at 18:04
I was looking for a way to create a large dummy file with space allocation recently. All of the solutions look awkward. Finally I just started the DISKPART
utility in Windows (embedded since Windows Vista):
DISKPART
CREATE VDISK FILE="C:\test.vhd" MAXIMUM=20000 TYPE=FIXED
Where MAXIMUM is the resulting file size, 20 GB here.

- 30,738
- 21
- 105
- 131

- 205
- 3
- 7
-
-
Doesn't work for me. No file is created unfortunately. I tried with administrator priviliges. – Magiranu Nov 20 '17 at 10:11
-
PowerShell one-liner to create a file in C:\Temp
to fill disk C: leaving only 10 MB:
[io.file]::Create("C:\temp\bigblob.txt").SetLength((gwmi Win32_LogicalDisk -Filter "DeviceID='C:'").FreeSpace - 10MB).Close

- 30,738
- 21
- 105
- 131

- 1,443
- 15
- 17
The simplest way I've found is this free utility: http://www.mynikko.com/dummy/
Creates dummy files of arbitrary size that are either filled with spaces or are filled with non-compressible content (your choice). Here's a screenshot:

- 183
- 1
- 3
Short of writing a full application, us Python guys can achieve files of any size with four lines, same snippet on Windows and Linux (the os.stat()
line is just a check):
>>> f = open('myfile.txt','w')
>>> f.seek(1024-1) # an example, pick any size
>>> f.write('\x00')
>>> f.close()
>>> os.stat('myfile.txt').st_size
1024L
>>>

- 30,738
- 21
- 105
- 131

- 83,368
- 10
- 76
- 104
-
1Installing Python to solve one problem is really overkill. Why not just use something built in such as Powershell or C# - https://gist.github.com/nadams810/6539070 (you don't even need Visual Studio to compile C# applications). – Natalie Adams Sep 12 '13 at 15:26
-
1They are built into Windows which is what the OP asked for (assuming your system is fully up to date). – Natalie Adams Sep 12 '13 at 18:22
-
1@NatalieAdams But this answer _is_ quite helpful if you've already got Python installed for solving other problems. :) – JuSTMOnIcAjUSTmONiCAJusTMoNICa Sep 13 '19 at 02:54
Use:
/*
Creates an empty file, which can take all of the disk
space. Just specify the desired file size on the
command line.
*/
#include <windows.h>
#include <stdlib.h>
int main (int argc, char* ARGV[])
{
int size;
size = atoi(ARGV[1]);
const char* full = "fulldisk.dsk";
HANDLE hf = CreateFile(full,
GENERIC_WRITE,
0,
0,
CREATE_ALWAYS,
0,
0);
SetFilePointer(hf, size, 0, FILE_BEGIN);
SetEndOfFile(hf);
CloseHandle(hf);
return 0;
}
-
1What is `int`? Will this work for a 5 GB file? Is this limited to 2 or 4 GB? That the third parameter to `SetFilePointer()` is 0 suggests it will not work for a 5 GB file. – Peter Mortensen Sep 08 '18 at 21:01
I found an excellent utility that is configurable at https://github.com/acch/genfiles.
It fills the target file with random data, so there are no problems with sparse files, and for my purposes (testing compression algorithms) it gives a nice level of white noise.

- 183
- 1
- 3

- 1,699
- 4
- 19
- 38
-
This utility is a single file Java application that should work on any platform with Java. – Paul Jul 23 '12 at 03:07
-
-
Plain ol' C... this builds under MinGW GCC on Windows XX and should work on any 'generic' C platform.
It generates a null file of a specified size. The resultant file is NOT just a directory space-occupier entry, and in fact occupies the specified number of bytes. This is fast because no actual writes occur except for the byte written before close.
My instance produces a file full of zeros - this could vary by platform; this program essentially sets up the directory structure for whatever data is hanging around.
#include <stdio.h>
#include <stdlib.h>
FILE *file;
int main(int argc, char **argv)
{
unsigned long size;
if(argc!=3)
{
printf("Error ... syntax: Fillerfile size Fname \n\n");
exit(1);
}
size = atoi(&*argv[1]);
printf("Creating %d byte file '%s'...\n", size, &*argv[2]);
if(!(file = fopen(&*argv[2], "w+")))
{
printf("Error opening file %s!\n\n", &*argv[2]);
exit(1);
}
fseek(file, size-1, SEEK_SET);
fprintf(file, "%c", 0x00);
fclose(file);
}
-
I suggest you to check how I formatted your code. And BTW. the question already has a very good answer, and the fseek+fwrite was already presented in Pyton and WinAPI so this is little of a help. It's nice however you've provided a complete example. +1 for that. But try to not re-answer already solved questions, its just waste of the time in which you could help someone a bit more :) – quetzalcoatl Aug 10 '12 at 22:34
Temp files should be stored in the Windows Temp Folder. Based on the answer from Rod you can use the following one liner to create a 5 GB temp file which returns the filename
[System.IO.Path]::GetTempFileName() | % { [System.IO.File]::Create($_).SetLength(5gb).Close;$_ } | ? { $_ }
Explanation:
[System.IO.Path]::GetTempFileName()
generates a random filename with random extension in the Windows Temp Folder- The Pipeline is used to pass the name to
[System.IO.File]::Create($_)
which creates the file - The file name is set to the newly created file with
.SetLength(5gb)
. I was a bit surprised to discover, that PowerShell supports Byte Conversion, which is really helpful. - The file handle needs to be closed with
.close
to allow other applications to access it - With
;$_
the filename is returned and with| ? { $_ }
it is ensured that only the filename is returned and not the empty string returned by[System.IO.File]::Create($_)

- 1
- 1

- 5,567
- 2
- 38
- 46
I found a solution using DEBUG at http://www.scribd.com/doc/445750/Create-a-Huge-File, but I don't know an easy way to script it and it doesn't seem to be able to create files larger than 1 GB.

- 6,381
- 3
- 34
- 47
-
2can't you create 5 files and then append them ? Create them simultaniously using threading, and then append them :D – dassouki Jun 11 '09 at 18:44
-
I don't know if I could thread it without doing programming, but yes, I can copy the file a few times to get the size I need. In my case I don't need the file itself to be 5GB, just the space used up. – Leigh Riffel Jun 11 '09 at 18:51
-
2Writing to multiple files using threading sounds like a terrible idea, given how slow hard drives are ... Also, appending them is fairly expensive in terms of time so that probably fails the "quick" criteria. – Joey Jun 11 '09 at 19:14
You can try this C++ code:
#include<stdlib.h>
#include<iostream>
#include<conio.h>
#include<fstream>
#using namespace std;
int main()
{
int a;
ofstream fcout ("big_file.txt");
for(;;a += 1999999999){
do{
fcout << a;
}
while(!a);
}
}
Maybe it will take some time to generate depending on your CPU speed...

- 37,963
- 15
- 156
- 475

- 21
- 1
... 1 MB file dummy.txt within few seconds.
echo "This is just a sample line appended to create a big file.. " > dummy.txt
for /L %i in (1,1,14) do type dummy.txt >> dummy.txt
See here : http://www.windows-commandline.com/how-to-create-large-dummy-file/

- 2,688
- 2
- 17
- 23

- 314
- 3
- 14
You can use the cat powershell command.
First create a simple text file with a few characters. The more initial chars you enter, the quicker it becomes larger. Let's call it out.txt. Then in Powershell:
cat out.txt >> out.txt
Wait as long as it's necessary to make the file big enough. Then hit ctrl-c to end it.

- 171
- 1
- 10
Simple answer in Python: If you need to create a large real text file I just used a simple while
loop and was able to create a 5 GB file in about 20 seconds. I know it's crude, but it is fast enough.
outfile = open("outfile.log", "a+")
def write(outfile):
outfile.write("hello world hello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello world"+"\n")
return
i=0
while i < 1000000:
write(outfile)
i += 1
outfile.close()
Quick to execute or quick to type on a keyboard? If you use Python on Windows, you can try this:
cmd /k py -3 -c "with open(r'C:\Users\LRiffel\BigFile.bin', 'wb') as file: file.truncate(5 * 1 << 30)"

- 21,433
- 16
- 79
- 117
Another GUI solution : WinHex.
“File” > “New” > “Desired file size” = [X]
“File” > “Save as” = [Name]
Contrary to some of the already proposed solutions, it actually writes the (empty) data on the device.
It also allows to fill the new file with a selectable pattern or random data :
“Edit” > “Fill file” (or “Fill block” if a block is selected)

- 141
- 4
In PowerShell...
$file = [System.IO.File]::Create("$pwd\1GB.dat")
$file.SetLength(1GB)
$file.Close()

- 139
- 8
I've made some additions to the same fsutil
method as mentioned in the chosen answer.
This is to create files of many different extensions and/or of various sizes.
set file_list=avi bmp doc docm docx eps gif jpeg jpg key m4v mov mp4 mpg msg nsf odt pdf png pps ppsx ppt pptx rar rtf tif tiff txt wmv xls xlsb xlsm xlsx xps zip 7z
set file_size= 1
for %%f in (%file_list%) do (
fsutil file createnew valid_%%f.%%f %file_size%
) > xxlogs.txt
The code can be cloned from https://github.com/iamakidilam/bulkFileCreater.git

- 99
- 3
- 14