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.
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
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
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[System.IO.File]::Create($_)
which creates the file.SetLength(5gb)
. I was a bit surprised to discover, that PowerShell supports Byte Conversion, which is really helpful..close
to allow other applications to access it;$_
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($_)
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 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...
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.