PDA

View Full Version : Check if file exists


jassel41
09-27-2011, 10:55 AM
Is there a way to check if a file exists in the current directory through code?

I don't want to access this file per say, I just want to verify that it already exists in the directory.

Thanks,
Jassel41

farshizzo
09-27-2011, 10:58 AM
You can use the os.path.isfile command to check for file existence.
import os
if os.path.isfile('foo.txt'):
print 'File exists'

jassel41
09-27-2011, 11:22 AM
That's perfect, thank you so much.