From d5a48997f366405b59949d4301aa3ae684805cc4 Mon Sep 17 00:00:00 2001 From: Valentin Date: Mon, 27 Apr 2020 14:55:10 +0800 Subject: [PATCH] Update documentation --- README.md | 6 ++--- doc/EpicPath.md | 72 ++++++++++++++++++++++++++++++++++++++++++++++++- doc/README.md | 2 +- 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 1095b05..ceadba0 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ This class aims to simplify high level operations with path # Context and history -I'm a Computing Student tired of creating again and again the same functions through all my projects to do the exact same thing... :tired_face: +I'm a Computing Student tired of creating again and again the same functions through all my projects to do the exact same things... :tired_face: Indeed, in every of my projects I create files, delete them, create folders and delete them *blablabla* ... -To solve this boring problem, I decided to create my own library that I can create one and only one time to use and reuse as many time as I wish to. +To solve this boring problem, I decided to create my own library that I can create one and only one time to use and reuse as many times as I wish to. And because I'm trying to be nice to this cruel world I share this *Epic* project with all of you :heart: -So feel free to download, use and give feedback about this ***epic*** creation. :+1: +So feel free to download it, use it and give feedback about this ***epic*** creation. :+1: # Description diff --git a/doc/EpicPath.md b/doc/EpicPath.md index 65345ce..d29fe6c 100644 --- a/doc/EpicPath.md +++ b/doc/EpicPath.md @@ -94,7 +94,7 @@ EpicPath('a/b/c/d/e/f/g/h/i/j/k/l') ## Add string to the path -`EpicPath` also support the `+` operator: +`EpicPath` also supports the `+` operator: ```python >>> p1 = EPath('a', 'b') @@ -238,3 +238,73 @@ This is the in place version of the method `.get_unique()`: >>> p1 EpicPath('text_1.txt') ``` + +# Get context information + +**`.listdir(t='epicpath', concat=False)`** + +The method `listdir(t='epicpath', concat=False)` lists all the files and folder in a directory +- The parameter `t` allows you to choose what type you want in the output list (`'epicpath'` (default) for `EpicPath`, `'path'` for `Path` and `'str'` for `str`) +- The parameter `concat=False` can be set to `True` to automatically include the current folder path in the output. + +```python +>>> p = EPath('a') + +>>> p.listdir() +[EpicPath('b'), EpicPath('setup.py'), EpicPath('file.txt')] +>>> p.listdir(t='path') +[WindowsPath('b'), WindowsPath('setup.py'), WindowsPath('file.txt')] +>>> p.listdir(t='str') +['b', 'setup.py', 'file.txt'] + +>>> p.listdir(concat=True) +[EpicPath('a/b'), EpicPath('a/setup.py'), EpicPath('a/file.txt')] + +``` + +**`.walk(t='epic')`** + +This method yields a generator as the function `os.walk`. The returned types are `EpicPath` for `t='epic'` (default), `Path` for `t='path'` and `str` for `t='str'`. + +```python +>>> path = EPath('a') +>>> for p in path.walk(): + ... print(p) +(EpicPath('a'), [EpicPath('b')], [EpicPath('setup.py'), EpicPath('file.txt')]) +(EpicPath('a/b'), [], [EpicPath('help.txt')]) +>>> for p in path.walk(t='path'): + ... print(p) +(WindowsPath('a'), [WindowsPath('b')], [WindowsPath('setup.py'), WindowsPath('file.txt')]) +(WindowsPath('a/b'), [], [WindowsPath('help.txt')]) +>>> for p in path.walk(t='str'): + ... print(p) +('a', ['b'], ['setup.py', 'file.txt']) +('a/b', [], ['help.txt']) +``` + +**`.walkfiles(t='epic')`** + +This method will return all the files encountered in a `.walk()` process. +The returned types are `EpicPath` for `t='epic'` (default), `Path` for `t='path'` and `str` for `t='str'`. + +```python +>>> path = EPath('a') +>>> for p in path.walkfiles(): + ... print(p) +setup.py # EpicPath object +file.txt # EpicPath object +help.txt # EpicPath object +>>> for p in path.walkfiles(t='path'): + ... print(p) +setup.py # WindowsPath object +file.txt # WindowsPath object +help.txt # WindowsPath object +>>> for p in path.walkfiles(t='str'): + ... print(p) +setup.py # string object +file.txt # string object +help.txt # string object +``` + + + diff --git a/doc/README.md b/doc/README.md index 39396a7..b842ad4 100644 --- a/doc/README.md +++ b/doc/README.md @@ -5,7 +5,7 @@ from epicpath import EpicPath as EPath ``` -I actually already created some aliases for you, so you can do all the fallowing import to get the same object: +I actually already created some aliases for you, so you can do all the fallowing imports to get the same object: ```python from epicpath import EpicPath # All these 3 imports are the same objects