Creating a file with $SIZE

Robert Bossy Robert.Bossy at
Wed Mar 12 13:52:03 CET 2008

k.i.n.g. wrote:
> I think I am not clear with my question, I am sorry. Here goes the
> exact requirement.
> We use dd command in Linux to create a file with of required size. In
> similar way, on windows I would like to use python to take the size of
> the file( 50MB, 1GB ) as input from user and create a uncompressed
> file of the size given by the user.
> ex: If user input is 50M, script should create 50Mb of blank or empty
> file
def make_blank_file(path, size):
    f = open(path, 'w') - 1)

I'm not sure the trick will work on all platforms, so you can:

def make_blank_file(path, size):
    f = open(path, 'w')
    f.write('\0' * size)


More information about the Python-list mailing list