py_utility_funcs.fileOps package¶
Submodules¶
py_utility_funcs.fileOps.dirFuncs module¶
-
py_utility_funcs.fileOps.dirFuncs.
get_dir_size
(path='.', display=False)¶ Get Size of a Directory
import py_utility_funcs.fileOps as puf dir_size = puf.get_dir_size(path = '.', display = False') puf.get_dir_size(path = '.', display = True')
Parameters: - path (str) – Path of the directory (Relative or Absolute) (Default is path of directory from where the python script is executed)
- display (bool, optional) – A flag used to print the size to the console (Default is False).
Returns: size – Total Size of the directory
Return type: integer
-
py_utility_funcs.fileOps.dirFuncs.
get_subdir_sizes
(dirName='.')¶ Print/Get Sizes of each sub folders in a Directory. (No recursion) Sizes are automatically displayed in KB/MB/GB/TB
import py_utility_funcs.fileOps as puf subdir_sizes = puf.get_subdir_sizes(dirName = '.')
Parameters: dirName (str) – Path of the directory [Relative or Absolute] (Default is path of directory from where the python script is executed) Returns: All the sub directory/folder sizes are displayed on terminal Return type: None
-
py_utility_funcs.fileOps.dirFuncs.
get_subdir_sizes_in_dataframe
(dirName='.', display_df=True)¶ Print/Get Sizes of each sub folders in a Directory sorted by size in descending order. (No recursion) Sizes are automatically displayed in MB. A pandas dataframe is also returned.
import py_utility_funcs.fileOps as puf subdir_sizes_df = puf.get_subdir_sizes_in_dataframe(dirName = '.', display_df=True)
Parameters: - dirName (str) – Path of the directory [Relative or Absolute]. (Default is path of directory from where the python script is executed).
- display_df (bool, optional) – Flag to indicate whether to display the dataframe in terminal (Default is True).
Returns: All the sub directory/folder sizes are displayed on terminal
Return type: None
py_utility_funcs.fileOps.fileFuncs module¶
-
py_utility_funcs.fileOps.fileFuncs.
file2list
(file, dtype=None)¶ Read a file and get its content to a list
import py_utility_funcs.fileOps as puf mylist = puf.file2list(file = 'your_file.txt')
Parameters: file (str) – Path/Name of the File (Relative or Absolute) Returns: listy – contents of the input file in a list Return type: list
-
py_utility_funcs.fileOps.fileFuncs.
find_file
(dirPath='.', regex='.txt')¶ Find Files in a directory by applying regular expression.
import py_utility_funcs.fileOps as puf found_files = puf.find_file(dirPath = '.', regex= '.py')
Parameters: - dirPath (str) – Path of the directory (Relative or Absolute) (Default is path of directory from where the python script is executed)
- regex (str, optional) – Regular Expression (Regex) to applied to search files (Default is /txt Files).
Returns: matchedFiles – file list matching the regex search
Return type: file list