Wednesday, April 2, 2008

Windows - Creating a blank file of specified size

The other day, i required a big file to test my application. First i thought i'd use Explorer.exe thinking it to be a really big file. But that turned out to be only 1Mb in size.
So googling around, i found some good solutions. I could find two ways to do it:

The first way:
fsutil file createnew <FileName> <Size
>
fsutil stands for File System Utility and it has quite some functionalities. Check them out by typing fsutil /? at the command prompt.
The parameter FileName is, obviously, the name of the file that you wish to create
Size is the size of the file which you want to create. This parameter needs to be specified in bytes. So if you wish to create a file of size 2Gb (2 * 1024 * 1024 * 1024), then you need to specify the size as: 2147483648.

The second way:
You will need cygwin to run this command on Windows, because this is a Unix command:
eg.
dd if=/dev/zero of=10mb-file.bin bs=1024k count=10
dd : Wikipedia says, "dd is a common UNIX program whose primary purpose is the low-level copying and conversion of raw data. dd is an abbreviation for "data definition" in IBM JCL, and the command's syntax is meant to be reminiscent of this."
if : Stands for Input File.
/dev/zero: Wikipedia explains this as, "In Unix-like operating systems, /dev/zero is a special file that provides as many null characters (ASCII NUL, 0x00; not ASCII character "digit zero", "0", 0x30) as are read from it."
of : Stands for Output File
bs : Block size
count : Copies only the specified number of input blocks
The command shown above creates a 10 Mb file.