By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,691 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

Finding the file availability

100+
P: 440
Hi ,

I would like to know whether the file is available at that particular location or not.
I/P:
Say 'C:\Sample\Sample.txt'

O/P:

If the file is available : Yes
If the file is not available : No


Thanks
PSB
May 15 '07 #1
Share this Question
Share on Google+
4 Replies


Motoma
Expert 2.5K+
P: 3,235
I am sure you could do with with stat(), but there are probably other ways of doing it as well. Opening it for reading will probably work too, if you interpret the result of the open call correctly.

Hi ,

I would like to know whether the file is available at that particular location or not.
I/P:
Say 'C:\Sample\Sample.txt'

O/P:

If the file is available : Yes
If the file is not available : No


Thanks
PSB
May 15 '07 #2

100+
P: 440
I am sure you could do with with stat(), but there are probably other ways of doing it as well. Opening it for reading will probably work too, if you interpret the result of the open call correctly.
Could you please a snippet of the code
May 15 '07 #3

bvdet
Expert Mod 2.5K+
P: 2,851
Expand|Select|Wrap|Line Numbers
  1. >>> import os
  2. >>> p = r'C:\SDS2_7.0\macro\Zip\tem.txt'
  3. >>> os.path.isfile(p)
  4. True
  5. >>> p = r'C:\SDS2_7.0\macro\Zip\tem.zip'
  6. >>> os.path.isfile(p)
  7. False
  8. >>> 
May 15 '07 #4

Expert 100+
P: 511
Expand|Select|Wrap|Line Numbers
  1. >>> filepath=os.path.join("/tmp","file")
  2. >>> if os.path.exists(filepath):
  3. ...   print "Found: " , filepath
  4. ...   if os.path.isfile(filepath):
  5. ...       print "%s is a file " % filepath
  6. ... 
  7.  
pls spend some time reading the docs on os, sys modules.
May 16 '07 #5

Post your reply

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