Reputation: 546
How to wait for a zip file to be located in folder to continue the code?
I have been working on the code bellow, but it proceeds even when the zip file is not in folder.
folder = os.listdir(path)
for file in folder:
print(file)
if not file.endswith('.zip'):
time.sleep(5)
if file.endswith('.zip'):
print('zip located')
break
else:
time.sleep(5)
Upvotes: 0
Views: 782
Reputation: 8045
Something to this effect should work:
import os
import time
while not '.zip' in [os.path.splitext(file)[1] for file in os.listdir(".")]:
time.sleep(2)
print('zip located')
Upvotes: 1