Check a path for existence and properties. Without arguments, return True if the path exists, otherwise False. valid checkers:: file = 1 # is a file file = 0 # is not a file (may not even exist) dir = 1 # is a dir link = 1 # is a
(self, **kw)
| 771 | return islink(self.strpath) |
| 772 | |
| 773 | def check(self, **kw): |
| 774 | """Check a path for existence and properties. |
| 775 | |
| 776 | Without arguments, return True if the path exists, otherwise False. |
| 777 | |
| 778 | valid checkers:: |
| 779 | |
| 780 | file = 1 # is a file |
| 781 | file = 0 # is not a file (may not even exist) |
| 782 | dir = 1 # is a dir |
| 783 | link = 1 # is a link |
| 784 | exists = 1 # exists |
| 785 | |
| 786 | You can specify multiple checker definitions, for example:: |
| 787 | |
| 788 | path.check(file=1, link=1) # a link pointing to a file |
| 789 | """ |
| 790 | if not kw: |
| 791 | return exists(self.strpath) |
| 792 | if len(kw) == 1: |
| 793 | if "dir" in kw: |
| 794 | return not kw["dir"] ^ isdir(self.strpath) |
| 795 | if "file" in kw: |
| 796 | return not kw["file"] ^ isfile(self.strpath) |
| 797 | if not kw: |
| 798 | kw = {"exists": 1} |
| 799 | return Checkers(self)._evaluate(kw) |
| 800 | |
| 801 | _patternchars = set("*?[" + os.sep) |
| 802 |