pyfan.util.path.getfiles

The pyfan.util.path.getfiles generate and get various file paths.

import pyfan.util.path.getfiles as getfiles

Includes method gen_path_file(), gen_path()

Module Contents

Functions

gen_path_file(spt_folder='', snm_file='', st_file_type='')

Return full path to file given folder path and file name with suffix

gen_path(spt_root='', main_folder_name='', sub_folder_name=None, subsub_folder_name=None)

Generate a file path and return it

fp_search_rglob(spt_root='../', st_rglob='*.py', ls_srt_subfolders=None, verbose=False)

Searches for files with search string in a list of folders

pyfan.util.path.getfiles.gen_path_file(spt_folder='', snm_file='', st_file_type='')[source]

Return full path to file given folder path and file name with suffix

Parameters
spt_folderstr

full path to folder

snm_filestr

file name without suffix (or with)

st_file_typestr

type of file, see options below, with pre-determined suffix, by default, there is no suffix. so if specify nothing, will save the snm_file with what is externally fed in

Returns
str

Full path to file with path and file name.

Examples

>>> gen_path_file(spt_folder = 'C:/Users/fan/logvig/parameters/combo_type/',
...               snm_file = 'fs_gen_combo_type_20201030', st_file_type='log')
C:\Users\fan\logvig\parameters\combo_type\fs_gen_combo_type_20201030.log.py
pyfan.util.path.getfiles.gen_path(spt_root='', main_folder_name='', sub_folder_name=None, subsub_folder_name=None)[source]

Generate a file path and return it

Parameters
spt_rootstr

root name

main_folder_namestr

folder name

sub_folder_namestr, optional

subfolder name

subsub_folder_namestr

subsub folder name

Returns
str

the full path to the folder

Examples

>>> gen_path(spt_root = 'C:/Users/fan/',
...          main_folder_name='logvig', sub_folder_name='parameters',
...          subsub_folder_name='combo_type')
C:\Users\fan\logvig\parameters\combo_type\
pyfan.util.path.getfiles.fp_search_rglob(spt_root='../', st_rglob='*.py', ls_srt_subfolders=None, verbose=False)[source]

Searches for files with search string in a list of folders

Parameters
spt_rootstring

root folder to search in

st_rglobstring

search for files with this rglob string

ls_srt_subfolderslist of str

a list of subfolders of the spt_root to search in

verbose: bool

print details

Returns
list of str

A list of file names

Examples

>>> ls_spn = fp_search_rglob(spt_root="../",
>>>                          ls_srt_subfolders=['rmd', 'pdf'],
>>>                          st_rglob = '*d*.py')
[WindowsPath('../rmd/bookdownparse.py'), WindowsPath('../rmd/mattexmd.py'), WindowsPath('../rmd/rmdparse.py'), WindowsPath('../pdf/pdfgen.py')]