469,592 Members | 1,772 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

search to see if a file exists

ironmonkey69
Can someone help me with a python script that can see if a file exists and to return a number if does or doesn't?
Aug 17 '07 #1
7 2026
ilikepython
844 Expert 512MB
Can someone help me with a python script that can see if a file exists and to return a number if does or doesn't?
Have you seen the os module? Try the os.phat.exists() function.
Aug 17 '07 #2
bartonc
6,596 Expert 4TB
Can someone help me with a python script that can see if a file exists and to return a number if does or doesn't?
Actually in os.path module:
exists( path)

Return True if path refers to an existing path. Returns False for broken symbolic links. On some platforms, this function may return False if permission is not granted to execute os.stat() on the requested file, even if the path physically exists.
Aug 18 '07 #3
ilikepython
844 Expert 512MB
Actually in os.path module:
Isn't that what the O/P wants? It return true if the path exists or false if it doesn't, right? That's how it works in my computer.
Aug 19 '07 #4
bartonc
6,596 Expert 4TB
Isn't that what the O/P wants? It return true if the path exists or false if it doesn't, right? That's how it works in my computer.
Yep:
Have you seen the os module? Try the os.phat.exists() function.
I was correcting the misspelling and pointing out the fact that os.path is documented separately.
Aug 19 '07 #5
ilikepython
844 Expert 512MB
Yep:I was correcting the misspelling and pointing out the fact that os.path is documented separately.
Oh, ok, I got you .
Aug 19 '07 #6
peruron
11
I've tried to use import os.path and then use "exists", but I get NameError: "NameError: name 'exists' is not defined"

As the path I wrote the file name itself, since it's located as the same directory as the script: exists(FileName)

Does anyone has an idea what is the problem here?
Aug 19 '07 #7
ilikepython
844 Expert 512MB
I've tried to use import os.path and then use "exists", but I get NameError: "NameError: name 'exists' is not defined"

As the path I wrote the file name itself, since it's located as the same directory as the script: exists(FileName)

Does anyone has an idea what is the problem here?
Either do:
Expand|Select|Wrap|Line Numbers
  1. from os.path import exists
  2. exists(FileName);
  3.  
or do:
Expand|Select|Wrap|Line Numbers
  1. import os.path
  2. os.path.exists(FileName)
  3.  
Aug 19 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by jcouse | last post: by
1 post views Thread by simon | last post: by
1 post views Thread by Todd Beaulieu | last post: by
9 posts views Thread by Lloyd Sheen | last post: by
3 posts views Thread by mercuryshipzz | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.