Module pywander.pathlib

Functions

def gen_allfile(startpath='.', filetype='')

利用os.walk 遍历某个目录,收集其内的文件,返回符合条件的文件路径名 是一个生成器。 第一个可选参数 startpath 默认值 '.' 第二个参数 filetype 正则表达式模板 默认值是"" 其作用是只选择某些文件 如果是空值,则所有的文件都将被选中。比如 "html$|pdf$" 将只选中 html和pdf文件。

def gen_filetree(startpath='.', filetype='')

利用os.walk 遍历某个目录,收集其内的文件,返回 (文件路径列表, 本路径下的文件列表) 比如: (['shortly'], ['shortly.py']) (['shortly', 'templates'], ['shortly.py']) (['shortly', 'static'], ['shortly.py'])

第一个可选参数 startpath  默认值 '.'
第二个参数  filetype  正则表达式模板 默认值是"" 其作用是只选择某些文件
如果是空值,则所有的文件都将被选中。比如 "html$|pdf$" 将只选中 html和pdf文件。
def get_project_path(dir=None)

返回mymodule存放的根目录

如果指定dir 则返回根目录下的一个文件

:param dir: :return:

def ls(path='.', glob=False)

like ls common, return Path object

if glob set to True, then you can use the glob language for ls.

def ls_dir(path='.', glob=False)

based on ls function, but only return directory.

def ls_file(path='.', glob=False)

based on ls function but only return file.

def mkdirs(path, mode=511)

Recursive directory creation function base on os.makedirs with a little error handling.

def normalized_path(path='.') ‑> str

默认支持 ~ 符号

返回的是字符串

which default support the ~

def normalized_path_obj(path='.') ‑> pathlib.Path

默认支持 ~ 符号

返回的是 Path 对象 :param path: :return:

def pwd()

get current directory

def rm(path, recursive=False)

the function can remove file or empty directory(default).

use shutil.rmtree to remove the non-empty directory,you need add recursive=True