Windows tip: quickly create a file of the given size and fill it
Posted: (EET/GMT+2)
Did you know that you can quickly and easily create a file with the given size from the Windows command prompt? Yes you can, and it only requires a simple usage of the "fsutil.exe" utility.
The usage is simple. To create a file in the current directory called "test.dat" and set its size to 5000 bytes, run the following command:
fsutil file createnew test.dat 5000
You can also create much larger files, up to terabytes (TB) in size. For instance, the following would create a file with 50 GiB in size:
fsutil file createnew test.dat 53687091200
Here, 53687091200 is 50 * 2^30 bytes. One gibibyte (old-school gigabyte) is 1024*1024*1024 bytes = 2^30 bytes.
You can also use PowerShell to call the same fsutil.exe routine. However, there's a nice thing that you can give large file sizes using convenient values. For instance, the above 50 GiB can be given as "(50GB)", as follows:
fsutil.exe file createnew test.dat (50GB)
With the createnew command, fsutil creates a file with the given size, and the content of the file is filled with NULL characters (ASCII code 0h). If you want to have some "valid" or "real" data in your file, you can use fsutil's another command called "setvaliddata". This sets the file contents to some random data that is nonetheless a good test for any disk system. Here's an example of using this command:
fsutil file setvaliddata test.dat 100
The last parameter is the number of bytes to set "valid". The number must be less or equal to the size of the file, and if you run the command twice on the same file, the number cannot be smaller than in the previous run. Finally, you must have administrator privileges to run this command ("Run as Administrator").
Here's how the valid data might look like:
AäâªH²R€.B7ïÀ0
Hope this helps!