Created
April 18, 2012 17:14
-
-
Save rnelson/2415150 to your computer and use it in GitHub Desktop.
Makes a big file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Based on http://stackoverflow.com/questions/982659/quickly-create-large-file-on-a-windows-system | |
import os | |
import sys | |
if len(sys.argv) != 3: | |
print 'usage: mkbigfile.py <filename> <size in gb>' | |
sys.exit(1) | |
# Grab the filename and requested size, convert the size to bytes | |
filename = sys.argv[1] | |
size = int(sys.argv[2]) * 1024 * 1024 * 1024 | |
# Make sure the file doesn't already exist | |
if os.path.exists(filename): | |
print 'error: file "' + filename + '" already exists' | |
sys.exit(-1) | |
# Make a big file | |
f = open(filename, 'w') | |
f.seek(size - 1) | |
f.write('\x00') | |
f.close() | |
# Quick test, make sure we're close to the right size | |
createdSize = os.stat(filename).st_size | |
if abs(size - createdSize) > 500: | |
print 'Created file seems to be the wrong size. My bad.' | |
sys.exit(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment