Sam
Sam

Reputation: 79

How to wait till a directory exist in Python (Ubuntu)

In my program, After some actions a directory will appear. but for the next commands to perform I have to wait until that directory appears. I can provide directory path and the name of the directory(It's for Ubuntu). I want to wait till that directory appears. How can I do this with Python code (in Ubuntu)?

Upvotes: 0

Views: 1339

Answers (2)

roippi
roippi

Reputation: 25964

In *nix you can take advantage of inotify to give you event-driven filesystem monitoring.

The most popular python library to my (and google's) knowledge at this time is pyinotify.

Upvotes: 5

Curt
Curt

Reputation: 1414

while True:
    if os.path.isdir("dir_path"): 
        break
    time.sleep(5)

Upvotes: 1

Related Questions