import os 
import sys 
import os.path 
def split(file, dirname): 
    if not os.path.isfile(file): 
        print file,"is not a file" 
        exit(1) 
    txtfile=open(file,"r") 
     
    #dirname='wikitxt'
     
    file_index=0 
     
    line_cnt = 0 
    for line in txtfile: 
        file_index+=1 
        if file_index % 100 == 0 :
        	print file_index 
        outfile=open(dirname+"/output_%d"%file_index+'.txt','w') 
        outfile.write(line);
    	outfile.close() 

    txtfile.close() 
                 
if __name__ == "__main__": 
    base_dir=os.path.dirname(os.path.abspath(sys.argv[0])) 
    root=os.path.join(base_dir,"wiki") 
    #print root 
    for rootdir,dirnames,filenames in os.walk(root): 
        for filename in filenames: 
            if not filename.endswith('.txt'): 
                continue 
            txtname=rootdir+"/"+filename 
            #print txtname 
            split(txtname,'wikitxt')