Найти - Пользователи
Полная версия: os.listdir() , "WindowsError: [Error 2] :"
Начало » Python для новичков » os.listdir() , "WindowsError: [Error 2] :"
1
alexzander77
Добрый день панове.
import os, sys,shutil,re,time

def fmove(p1,p2):
if not os.path.exists(p1):return p1+' does not exists '
if not os.path.exists(p2):return p2+' does not exists '
shutil.move(p1,p2)
return False

class logscan:
def __init__(self):
self.inname='./in/'
self.tmpname='./in/temp/'
self.badname='./in/temp/bad/'
self.okayinname='./in/temp/okayin/'
self.sleeptime=5

def scaner(self):
# if tmp : print tmp
tmp=os.listdir(self.inname)
# print tmp
for f in tmp:
pathname = os.path.normpath(os.path.join(self.inname, f))
if os.path.isfile(pathname) and not os.path.islink(pathname):
self.logistic(pathname)
break

def logistic(self,pathname):
(dirname,filename)=os.path.split(pathname)
print 'found = ' ,filename,
m = fmove(pathname,self.tmpname)
if m :
print m
return
else:
print ', moved',
self.tester(filename)

def tester(self,filename):
print ', tst:',
os.chdir(self.tmpname)
res = os.popen3('7z t '+filename+ ' ', 't')[1].read()
res2=re.search('(Everything is Ok)',res)
if res2:
print res2.group(),
else:
res2=re.search('(Error:)(.*)\n',res)
if res2:print res2.group(),
#print res2
print ', ',

def run(self):
while True:
fff=self.scaner()
if fff : self.logistic(fff)
time.sleep(self.sleeptime)

###############################################################################
print '<<<start>>>'
l=logscan()
l.run()
результат -
<<<start>>>
found = 111114.008 , moved , tst: Everything is Ok ,
Traceback (most recent call last):
File “<string>”, line 74, in run_nodebug
File “D:\_code\h_logscan\LogScan.py”, line 71, in <module>
l.run()
File “D:\_code\h_logscan\LogScan.py”, line 61, in run
fff=self.scaner()
File “D:\_code\h_logscan\LogScan.py”, line 26, in scaner
tmp=os.listdir(self.inname)
WindowsError: : ‘./in/*.*’
тоесть при втором вызове os.listdir(self.inname) выпадает ошибка.

в чем я недосмотрел?

спасибо )
alexzander77
хм.
расскажи другому - сам поймешь.

я менял активную директорию,
os.chdir(self.tmpname)
и не возвращал назад

Спасибо за внимание)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB