用python将提取的文件刷新到磁盘
这是我的代码:用python将提取的文件刷新到磁盘,python,Python,这是我的代码: x=zipfile.ZipFile('C://X/malware.zip') for i in range(1): x.extractall('C://E',pwd='infected') start=time.clock() print str(start) while flag==1: if os.path.exists('C://E/malware.exe')=
x=zipfile.ZipFile('C://X/malware.zip')
for i in range(1):
x.extractall('C://E',pwd='infected')
start=time.clock()
print str(start)
while flag==1:
if os.path.exists('C://E/malware.exe')==True:
flag=1
else:
flag=0
finish=time.clock()
print str(finish)
elapsed=finish-start
print "the time elapsed is " + str(elapsed)+"seconds"
我需要将提取直接写入磁盘,,,如何刷新正在提取的文件,,,,?您似乎认为需要等待zip文件被提取。Python不是这样工作的。当
x.extractall()
完成时,就完成了。文件已被提取并关闭,因此已刷新到磁盘
此外,即使您确实需要等待,这:
while flag==1:
if os.path.exists('C://E/malware.exe')==True:
flag=1
else:
flag=0
在很多方面都是错误的,我甚至不知道从哪里开始。但最好写为:
while not os.path.exists('C://E/malware.exe'):
time.sleep(0.01) # don't use all the CPU by checking constantly!
我的代码必须计算从病毒提取到被病毒扫描和删除的时间,,,请,如果你有比这更准确的想法,告诉我,