views:

5586

answers:

9

In the same vein as http://stackoverflow.com/questions/257844/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 5GB. 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.

+5  A: 

Check the windows resource kit.

http://www.microsoft.com/Downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

There is a utility called

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

Byron Whitlock
I'd rather not have to download the resource kit.
Leigh Riffel
you would only need the 1 exe from the resource kit, you don't have to have the whole thing on your production system.
Byron Whitlock
I'll give it a try, but I'd rather not have the additional file dependency.
Leigh Riffel
The file isn't downloading correctly for me now, but I can't imagine it being faster than the Contig tool mentioned by Johannes Rossel.
Leigh Riffel
+1  A: 

Short of writing a full application, us Python guys can achieve files of any size with 4 lines, same snippet on Windows and Linux (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
>>>
gimel
+1  A: 

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.

Leigh Riffel
can't you create 5 files and then append them ? Create them simultaniously using threading, and then append them :D
dassouki
I don't know if I could thread it without doing programming, but yes, I can copy the file a few times to get the size I need. In my case I don't need the file itself to be 5GB, just the space used up.
Leigh Riffel
Writing to multiple files using threading sounds like a terrible idea, given how slow hard drives are ... Also, appending them is fairly expensive in terms of time so that probably fails the "quick" criteria.
Joey
+1  A: 

You can use the Sysinternals Contig tool. It has a -n switch which creates a new file of a given size. It will create a file almost instantaneous.

Joey
Wow! Very fast to download and to run. The line I used is m:\contig -n M:\SpaceBuffer.tmp 5368709120
Leigh Riffel
+2  A: 
/*
creates an empty file, which can take 
all of the disk space. Just specify the desired file
size in 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;
}
lkurts
+12  A: 

fsutil file createnew <filename> <length>

where <length> is in bytes.

Patrick Cuff
Excellent, this is exactly what I was looking for.
Leigh Riffel
A: 

Blooming Big File. Google it. It quickly creates big files on Windows machines.

eddy
A: 

Hey i know this is an older thread but i was wondering if any of you would know how to make an incremental naming solution for this .bat file Leigh was working on here. for instance if you had contig -n I:\SpaceBuffer.tmp 5368709120 and you wanted to make it do a loop:

set number for (parameters) {

contig -n I:\SpaceBuffer%number%.tmp 5368709120 number++ } How would someone do this in a .bat file. I have taken intro Comp Sci classes in school but honestly i'm complete rubbish at programming and unless i've seen something hashed out for me I really can't do it.

teddy
I suggest you ask this as a separate question. You'll get more people to look at it and both you and the answerer will earn reputation.
Leigh Riffel
A: 

In cmd prompt: fsutil file createnew c:\temp\100MBfile.txt 104857600

Mario
@Mario Thank you, but this is already the accepted answer. You are welcome to vote for the accepted answer and you may want to consider deleting your answer to avoid it getting down votes for being a duplicate.
Leigh Riffel