#! /usr/bin/env python # VERSION 1.0 # copyleft Harvey Greenberg hgreen@u.washington.edu # This assumes that you have a series of files (.e.g. NAIP image files) # which are broken into gigabyte chunks named fname.a, fname.b, etc. # to be concatenated into fname. The .a file is renamed, while the # remaining files are appended to it. # RHEL tests show a megabyte buffer slightly better than a kilobyte # # e.g. cat.py # If python is not in your searchpath, you should add it: # That can be done in XP with Settings/ControlPanel/System/Advanced/EnvironmentalVariables. # or call python explicitly, .e.g. c:\Python24\python cat.py # ESRI users have python installed, generally in c:\Python24 # (or c:\Python21 for older versions). # # There are no arguments. This will append every set in this directory. import string import sys import os roots=[] nroots=0 fl = os.listdir('.') for fil in fl: if fil[-2:] != '.a': continue roots.append(fil[:-1]) nroots=nroots+1 print "Files to process:",roots for root in roots: count=0 for fil in fl: if fil[:-1] == root: count = count+1 print "There are",count,"pieces to",root size=os.stat(root+string.ascii_lowercase[count-1])[6] # print "Last file is",root+string.ascii_lowercase[count-1] if size == 1073741824L: print "The last component "+root+string.ascii_lowercase[count-1]+" is one gigabyte, so there is probably a missing file." print "We are skipping this set." continue for n in range(count): if n < (count-1): # if not the last component size=os.stat(root+string.ascii_lowercase[n])[6] # print size,root+string.ascii_lowercase[n] if size != 1073741824L: print "Size of "+root+string.ascii_lowercase[n]+" is only "+`size`+", not one gigabyte." print "We are skipping this set." break if n == 0: os.rename(root+"a",root[:-1]) g=open(root[:-1],"ab") else: print "Opening",string.ascii_lowercase[n],size f=open(root+string.ascii_lowercase[n],"rb") while 1: buffer=f.read(1048576) #RHEL tests show a megabyte buffer slightly better than a kilobyte g.write(buffer) if len(buffer) != 1048576: f.close() break if n == (count-1): # last component g.close()