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.
-
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. Dec 22, 2010 at 13:50
-
23
-
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 :) May 10, 2014 at 21: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
Oct 20, 2017 at 6:29 -
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. Oct 5, 2018 at 7:43
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.
-
2Wow! Very fast to download and to run. The line I used is m:\contig -n M:\SpaceBuffer.tmp 5368709120 Jun 11, 2009 at 19:52
-
6Just want to check if this is a sparse file or does the file actually have data in it?– slolifeJun 2, 2011 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 SJan 4, 2018 at 16:22
-
3@JasonS:
contig
effectively goes to the last byte and writes a single0
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.– JoeyJan 7, 2018 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. Aug 26, 2014 at 9: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.– MagiranuNov 20, 2017 at 10:20
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 :-)
-
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. Jun 18, 2013 at 1: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.– GabrielBJul 15, 2019 at 15:47
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.
-
3nice solution! Helpful if you have a variety of applications running, to get different sizes May 12, 2017 at 14:57
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.
-
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.– SamirNov 2, 2013 at 21:19
-
What operating system did you use here mate? The
rm
is a Unix/Linux command, whiledel
is a DOS/Windows command?...– SamirNov 2, 2013 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
.– SamirNov 2, 2013 at 21:50 -
@Sammy: It starts with
@echo off
, so it's obviously a.bat
. That's why it had double percent signs. Nov 2, 2013 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 createfile-4gb.txt
on that line? Or rename the oldfile-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 probablyren
. Likeren file-big.txt file-4gb.txt
. I think you confused that withrm
.– SamirNov 2, 2013 at 22:01
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.
-
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. Jun 11, 2009 at 18:51
-
1I'll give it a try, but I'd rather not have the additional file dependency. Jun 11, 2009 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. Jun 11, 2009 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.– SamirNov 2, 2013 at 17:45
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.
-
-
Doesn't work for me. No file is created unfortunately. I tried with administrator priviliges.– MagiranuNov 20, 2017 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
-
4
-
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
>>>
-
1Installing Python to solve one problem is really overkill. Why not just use something built in such as Powershell or C# - gist.github.com/nadams810/6539070 (you don't even need Visual Studio to compile C# applications). Sep 12, 2013 at 15:26
-
1They are built into Windows which is what the OP asked for (assuming your system is fully up to date). Sep 12, 2013 at 18:22
-
1@NatalieAdams But this answer is quite helpful if you've already got Python installed for solving other problems. :) Sep 13, 2019 at 2:54
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:
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 toSetFilePointer()
is 0 suggests it will not work for a 5 GB file. Sep 8, 2018 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.
-
This utility is a single file Java application that should work on any platform with Java.– PaulJul 23, 2012 at 3:07
-
-
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.
-
2can't you create 5 files and then append them ? Create them simultaniously using threading, and then append them :D– dassoukiJun 11, 2009 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. Jun 11, 2009 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.– JoeyJun 11, 2009 at 19:14
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($_)
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 :) Aug 10, 2012 at 22:34
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...
-
1The poster asked quickly. This would require installing a C++ compiler.– user1537415Feb 19, 2015 at 13:34
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.
... 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/
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)"
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)
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()
In PowerShell...
$file = [System.IO.File]::Create("$pwd\1GB.dat")
$file.SetLength(1GB)
$file.Close()
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