#This program was created with feed back from: smeghead and sirup plus aum of I2P; and also tiissa and John Machin of comp.lang.python
#Thank you very much.
#I still get the odd error in this, but it was 1 out of 2500 files successfully sorted. Make sure you have a directory under c:/test/called 'aa' and have your
#I release this code into the public domain :o), send feed back to sm.synonymous@gmail.com
import pickle
import os
import shutil
os.chdir ( '/test')
aaaa=2
aa='aa'
x=0
y=20
while y <> 2:
print y
List = []
for fileName in os.listdir ( '/test/' ):
Directory = fileName
List.append(Directory)
List.append("A111111111111")
List.sort()
List.append("Z111111111111")
ListLength = len(List) - 1
x = 0
while x < ListLength:
ListLength = len(List) - 1
b = List[x]
c = List[x + 1]
backward1 = List[x - 1]
d = b[:y]
e = c[:y]
backward2 = backward1[:y]
f = str(d)
g = str(e)
backward3 = str(backward2)
if f==g:
if os.path.isdir (aa+"/"+f) == True:
shutil.move(b,aa+"/"+f)
else:
os.mkdir(aa+"/"+f)
#os.mkdir(f)
shutil.move(b,aa+"/"+f)
else:
if f==backward3:
if os.path.isdir (aa+"/"+f) == True:
shutil.move(b,aa+"/"+f)
else:
os.mkdir(aa+"/"+f)
#os.mkdir(f)
shutil.move(b,aa+"/"+f)
else:
aaaa=3
x = x + 1
y = y - 1