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

Testing files

P: 63
Is there anyway to check if an argument is a file or directory?


Like `test -d .` in bash
Nov 30 '06 #1
Share this Question
Share on Google+
3 Replies


bartonc
Expert 5K+
P: 6,596
Is there anyway to check if an argument is a file or directory?

Like `test -d .` in bash
In the os package, in the path module, these functions appear:

isabs( path)
Return True if path is an absolute pathname (begins with a slash).

isfile( path)
Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path.

isdir( path)
Return True if path is an existing directory. This follows symbolic links, so both islink() and isdir() can be true for the same path.

for example:

>>> from os.path import *
>>> isdir(r"C:\Program Files")
True
>>>
Nov 30 '06 #2

P: 63
iLL
In the os package, in the path module, these functions appear:

isabs( path)
Return True if path is an absolute pathname (begins with a slash).

isfile( path)
Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path.

isdir( path)
Return True if path is an existing directory. This follows symbolic links, so both islink() and isdir() can be true for the same path.

for example:

>>> from os.path import *
>>> isdir(r"C:\Program Files")
True
>>>

Thank you!
Nov 30 '06 #3

bartonc
Expert 5K+
P: 6,596
Thank you!
You're welcome! Keep posting,
Barton
Nov 30 '06 #4

Post your reply

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