Quickly create large file on a Windows system

WindowsBatch File

Windows Problem Overview


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.

Windows Solutions


Solution 1 - Windows

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.

Solution 2 - Windows

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.

Solution 3 - Windows

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...

Solution 4 - Windows

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 :-)

Solution 5 - Windows

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.

Solution 6 - Windows

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.

Solution 7 - Windows

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.

Enter image description here

Enter image description here

Solution 8 - Windows

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

Solution 9 - Windows

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
>>>

Solution 10 - Windows

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;
}

Solution 11 - Windows

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.

Solution 12 - Windows

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.

Solution 13 - Windows

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.

Solution 14 - Windows

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);
}

Solution 15 - Windows

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($_)

Solution 16 - Windows

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:

enter image description here

Solution 17 - Windows

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...

Solution 18 - Windows

... 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/

Solution 19 - Windows

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.

Solution 20 - Windows

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()

Solution 21 - Windows

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)"

Solution 22 - Windows

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)

Solution 23 - Windows

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLeigh RiffelView Question on Stackoverflow
Solution 1 - WindowsPatrick CuffView Answer on Stackoverflow
Solution 2 - WindowsJoeyView Answer on Stackoverflow
Solution 3 - WindowsGiriView Answer on Stackoverflow
Solution 4 - WindowsZXXView Answer on Stackoverflow
Solution 5 - Windowsf.ardelianView Answer on Stackoverflow
Solution 6 - WindowsByron WhitlockView Answer on Stackoverflow
Solution 7 - WindowsshenkuView Answer on Stackoverflow
Solution 8 - WindowsRodView Answer on Stackoverflow
Solution 9 - WindowsgimelView Answer on Stackoverflow
Solution 10 - WindowslkurtsView Answer on Stackoverflow
Solution 11 - WindowschersunView Answer on Stackoverflow
Solution 12 - WindowsMusikPoliceView Answer on Stackoverflow
Solution 13 - WindowsLeigh RiffelView Answer on Stackoverflow
Solution 14 - WindowsBill WView Answer on Stackoverflow
Solution 15 - WindowsFlorian FeldhausView Answer on Stackoverflow
Solution 16 - Windowsyosh mView Answer on Stackoverflow
Solution 17 - WindowsNEt_BomberView Answer on Stackoverflow
Solution 18 - WindowsCKuharskiView Answer on Stackoverflow
Solution 19 - WindowsMeghdadView Answer on Stackoverflow
Solution 20 - WindowsjkdbaView Answer on Stackoverflow
Solution 21 - WindowsNoctis SkytowerView Answer on Stackoverflow
Solution 22 - WindowsGabrielBView Answer on Stackoverflow
Solution 23 - WindowsAlan PallathView Answer on Stackoverflow