Programmet ska söka rekursivt och det är det som får felmeddelanden hela tiden.
Här är koden:
Kod: Markera allt
#!/usr/bin/env python
import os, sys
homedir = os.path.expanduser("~")
desktop = os.getcwd()
pf = [".jpg", ".gif", ".tif", ".png", ".svg", ".jpe", ".jpeg", ".tiff"]
headdirs = []
files = []
founds = []
subdirs = [ [] , [ ] ]
headdir = os.path.realpath("./")
def add_subdir(indir, subdir):
try:
p = subdirs[0].index(indir)
subdirs[1][p].append(subdir)
except:
subdirs[0].append(indir)
subdirs[1].append([subdir])
def get():
dirfiles = os.listdir("./")
cnum = len(dirfiles) - 1
loop = 1
while loop == 1:
try:
tmp = os.path.realpath(dirfiles[cnum])
if os.path.isdir(tmp) == True:
add_subdir(os.path.realpath("./"), tmp)
elif os.path.islink == True:
pass
else:
files.append(tmp)
del dirfiles[cnum]
except:
pass
if len(dirfiles) == 0:
wdir = os.path.realpath("./")
i = subdirs[0].index(wdir)
subd = len(subdirs[1][i])
dirlist = subdirs[1][i]
cdir = dirlist[subd-1]
num = dirlist.index(cdir)
while subd > 0:
os.chdir(cdir)
del subdirs[1][i][num]
dirfiles = os.listdir("./")
cnum = len(dirfiles) - 1
else:
cnum = cnum - 1
def search(output=""):
dirfiles = os.listdir("./")
num = len(files)
place = 0
while num > 0:
tmp = files[place]
if os.path.isdir(tmp) == False:
if len(tmp) > 5:
if test(tmp)[0] == True:
founds.append(tmp)
else:
headdirs.append(os.path.realpath("./"))
if os.path.islink == True:
x = headdirs.index("./")
del dirs[x]
else:
os.chdir(tmp)
place = place + 1
num = num - 1
if num == 0:
numdir = len(dirs)
while numdir > 0:
os.chdir(dirs[numdir-1])
del dirs[numdir-1]
search()
numdir = len(dirs)
def test(ifile):
status = False
if len(ifile) > 5:
times = len(aff)
while times > 0:
app = aff[times-1]
if ifile[-len(app):] == app:
status = True
times = times - 1
return [status, ifile]
#try:
# search()
#except RuntimeError:
# print "Oops, too much at the same time!"
get()
numfounds = len(founds)
founds.reverse()
while numfounds > 0:
print founds[numfounds-1]
del founds[numfounds-1]
numfounds = len(founds)
P.S Det är GPL och får kopieras
