Last active
September 24, 2020 07:59
-
-
Save qnkhuat/775eb55ad3137ca454159994a89ca462 to your computer and use it in GitHub Desktop.
Extend methods of Path from pathlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pathlib import Path | |
from glob import glob | |
Path.ls = lambda x : [o.name for o in x.iterdir()] | |
Path.ls_p = lambda x : [str(o) for o in x.iterdir()] | |
Path.str = lambda x : str(x) | |
def insensitive_glob(root, pattern): | |
def either(c): | |
return '[%s%s]' % (c.lower(), c.upper()) if c.isalpha() else c | |
return root.glob(''.join(map(either, pattern))) | |
Path.icglob = lambda root, pattern : insensitive_glob(root, pattern) | |
# usage: Path("~/Desktop").icglob("*/.jpg") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment