1
I have several files inside a directory called imagex
, about 5,000 images.
A simple example of a file:
file_path = "C:/imagex/jonsnow.png"
How to step check, efficiently, if there is a specific image inside this directory?
1
I have several files inside a directory called imagex
, about 5,000 images.
A simple example of a file:
file_path = "C:/imagex/jonsnow.png"
How to step check, efficiently, if there is a specific image inside this directory?
1
Here’s what you can do, using os.pathexists.:
import os
file_path = "C:/imagex/jonsnow.png"
if os.path.exists(file_path):
# existe seja arquivo ou diretorio
To check only files you can do:
...
if os.path.isfile(file_path):
# existe e e ficheiro
...
Funfou aqui! = ) Tks
You’re welcome @Acklay
Browser other questions tagged python
You are not signed in. Login or sign up in order to post.
Related and perhaps duplicated: http://answall.com/questions/133366/verifica-se-existe-arquivo-se-existi-report-python-blibioteca-os
– Miguel
@Miguel I guess I didn’t look hard enough, I hadn’t seen that question there.
– viana
Quiet, no problem, anyway the answer this goes straight to the question
– Miguel