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 | class="st">"""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 class="cm"># is a file |
| 781 | file = 0 class="cm"># is not a file (may not even exist) |
| 782 | dir = 1 class="cm"># is a dir |
| 783 | link = 1 class="cm"># is a link |
| 784 | exists = 1 class="cm"># exists |
| 785 | |
| 786 | You can specify multiple checker definitions, for example:: |
| 787 | |
| 788 | path.check(file=1, link=1) class="cm"># a link pointing to a file |
| 789 | class="st">""" |
| 790 | if not kw: |
| 791 | return exists(self.strpath) |
| 792 | if len(kw) == 1: |
| 793 | if class="st">"dir" in kw: |
| 794 | return not kw[class="st">"dir"] ^ isdir(self.strpath) |
| 795 | if class="st">"file" in kw: |
| 796 | return not kw[class="st">"file"] ^ isfile(self.strpath) |
| 797 | if not kw: |
| 798 | kw = {class="st">"exists": 1} |
| 799 | return Checkers(self)._evaluate(kw) |
| 800 | |
| 801 | _patternchars = set(class="st">"*?[" + os.sep) |
| 802 |