The indentation matters in python so take care to preserve that.
I called it loader.py but you can call it whatever you want.
First argument is the starting directory you want to cache. It will walk recursively down from there.
Second argument is the file pattern to read.
I use this to load up all the WoW files before starting the game.
Code: Select all
C:\Python27> python loader.py L:\WoW\Data *.*
Code: Select all
import os, fnmatch, sys, argparse, fileinput
def find_files(directory, pattern):
for root, dirs, files in os.walk(directory):
for basename in files:
if fnmatch.fnmatch(basename, pattern):
filename = os.path.join(root, basename)
yield filename
bufsize=1024*1024*256
for filename in find_files(sys.argv[1], sys.argv[2]):
print 'Loading:', filename,
fh=open(filename, 'rb')
while True:
data=fh.read(bufsize)
print '.',
if not data: break
fh.close()
del data
print "done"