#!/usr/bin/env python import glob import os import shutil L = range(1, 100) for i in glob.glob('*.html'): if len([x for x in i if x.isdigit()]) == 0: #if it contains a number dir = i[:-5] #remove the '.html' if dir not in glob.glob('*'): os.mkdir(dir) #create the directory which is named i up to .html shutil.copy(i, dir) #copy the files to the directory for y in glob.glob('./*-[1-100].html'): #remove all files that contain numbers os.remove(y) file = open('howtofixoutput.txt', 'w') #open file to output the redirect files file.write(i + '\n') file.close() file2 = open('howtofixoutput.txt', 'r') #reopen file to output the redirect filenames print file2.readlines() #print the redirect filenames