scistag.filestag.file_path.FilePath¶
- class FilePath[source]¶
Bases:
objectHelper class for handling file paths - such as detecting the path or the extension of a file.
Methods
Returns the absolute path for given relative path (relative to the current getcwd() path.
Returns the absolute, normalized path of a relative path object combined with an absolute path object.
Returns the path's base name (e.g the filename)
Returns the directory name of a file
Returns if given path exists
Creates the defined directory and all directories in between
Normalizes a path, e.g.
Returns the file name of the calling method
Returns the file name of the calling method
Returns the extension and file component of given file path
Returns the single path components as a list
Attributes
The OS specific path separator
__dict____doc____module____weakref__list of weak references to the object (if defined)
- classmethod absolute(path)[source]¶
Returns the absolute path for given relative path (relative to the current getcwd() path.
As of now just a wrapper of os.path.abspath().
- Parameters
path (
str) – The relative path e.g. “./../data”- Returns
The absolute path, e.g. “/home/user/scripts/data”
- classmethod absolute_comb(rel_path, absolute_path=None)[source]¶
Returns the absolute, normalized path of a relative path object combined with an absolute path object.
What makes this function pretty handy is that if no path is given the calling script’s path or Jupyter notebook’s path will be used so relative includes can be easily located.
- Parameters
- Returns
The absolute path
- static basename(path)[source]¶
Returns the path’s base name (e.g the filename)
As of now just a wrapper of os.path.basename().
- static dirname(filename, slash=True)[source]¶
Returns the directory name of a file
As of now just a wrapper of os.path.dirname().
- static exists(path)[source]¶
Returns if given path exists
As of now just a wrapper of os.path.exists().
- classmethod make_dirs(path, exist_ok=False)[source]¶
Creates the defined directory and all directories in between
- static norm_path(path, slash=True)[source]¶
Normalizes a path, e.g. integrates relative path definitions such as .. and . into the path.
As of now just a wrapper of os.path.normpath().
- Parameters
- Return type
- Returns
The “cleaned” path, e.g. The path, e.g. /home/user/documents
- classmethod script_filename(level=1)[source]¶
Returns the file name of the calling method
- Parameters
level – The stack level relative to this function, for internal use only. (+1 = caller, +2 = caller’s caller etc.)
- Return type
- Returns
The absolute filename of the script file
- classmethod script_path(level=1)[source]¶
Returns the file name of the calling method
- Parameters
level – The stack level relative to this function, for internal use only. (+1 = caller, +2 = caller’s caller etc.)
- Return type
- Returns
The absolute filename of the script file
- classmethod split_ext(filename)[source]¶
Returns the extension and file component of given file path
As of now just a wrapper of os.path.split_ext().
- classmethod split_path_components(path_name)[source]¶
Returns the single path components as a list
As of now just a wrapper of os.path.split().
- SEP = '/'¶
The OS specific path separator