Windows – How to Generate File of a determinate Size in Windows

filefilesystemsscriptingwindows

How is the Best and fastest way to do it?

Best Solution

PowerShell:

$f = new-object System.IO.FileStream c:\temp\test.dat, Create, ReadWrite
$f.SetLength(42MB)
$f.Close()

This will create a file c:\temp\test.dat that consists of 42MB of nullbytes. You can of course just give byte count instead as well. (42MB = 42 * 1048576 for PowerShell)