guialmachado
guialmachado

Reputation: 546

Python to wait for zip file to be in folder

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

Answers (1)

felipe
felipe

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

Related Questions