file¶
- file.change_suffix(filename, suffix=False):
Change the suffix of the file /some/path/my.file –> /some/path/my.othersuffix
- Parameters:
filename (
str) – The filenamesuffix (
str) – The new suffix (must start with a .). If omitted the suffix will be stripped.
- Returns:
The filename with the new suffix
- Return type:
str
- file.copy(src, dst, force_overwrite=False, **kwargs):
not documented yet
- file.delete(path, recursive=False):
not documented yet
- file.dir(path, pattern='*', **kwargs):
not documented yet
- file.exists(filename):
Check if filename exists
- Parameters:
filename (
str) – The filename- Returns:
True if it exists, False if not
- Return type:
bool
- file.get_filename(filename):
Get only the filename /some/path/my.file –> my.file
- Parameters:
filename (
str) – The filename- Returns:
Filename without path
- Return type:
str
- file.get_suffix(filename):
Get the suffix from the filename /some/path/my.file –> file
- Parameters:
filename (
str) – The filename- Returns:
The suffix
- Return type:
str
- file.is_dir(filename):
Check if filename is a directory
- Parameters:
filename (
str) – The filename- Returns:
True if it is a directory, False if not
- Return type:
bool
- file.is_file(filename):
Check if filename is a file
- Parameters:
filename (
str) – The filename- Returns:
True if it is a file, False if not
- Return type:
bool
- file.load(path, **kwargs):
Load data from a textfile. This function works for local paths an http/https hosted files.
- Parameters:
path (
str) – Can be a local path or a http/https URL. For relative paths the current task base directory is set as basepath so test.txt will become /path/to/task/test.txt- Returns:
On error opening the File False is returned. On success the content of the textfile is returned.
- Return type:
boolorstr- Keyword Arguments:
None at the moment.
- file.mkdir(filename, mode=511, parents=False, exist_ok=False):
Create directory
- Parameters:
filename (
str) – The path of the directorymode (
int) – The mode that should be set for the directoryparents (
bool) – If parents is true, any missing parents of this path are created as needed; they are created with the default permissions without taking mode into account (mimicking the POSIX mkdir -p command). If parents is false (the default), a missing parent raises FileNotFoundError.exist_ok (
bool) – If exist_ok is true, FileExistsError exceptions will be ignored (same behavior as the POSIX mkdir -p command), but only if the last path component is not an existing non-directory file. If exist_ok is false (the default), FileExistsError is raised if the target directory already exists.
- Returns:
True if creation was successful
- Return type:
bool
- file.mkdir_p(filename):
Create directory and all parents if the do not exist. Will basically do what “mkdir -p” does and uses the mkdir-function in this lib - lazy function for lazy ppl
- Parameters:
filename (
str) – The path of the directory- Returns:
True if creation was successful
- Return type:
bool
- file.move(src, dst, force_overwrite=False, **kwargs):
not documented yet
- file.open(url, flags='r'):
Opens files from local filesystem or http/https/ftp and returns a corresponding descriptor
- Parameters:
url (
str) – URLflags (
str, optional) – flags that should be passed to python open see https://docs.python.org/3/library/functions.html#open , defaults to “r”
- Returns:
File descriptor to local file or file served via http/https
- Return type:
file
- file.resolve(fn=':inmemory:'):
Return the absolute path of the parent directory of the file
- Parameters:
fn (
str) – The filename. Defaults to __file__- Returns:
Absolute path of the files directory
- Return type:
str
- file.resolve_path(path):
not documented yet
- file.rmdir(path, recursive=False):
Remove a directory. Can be recursive if
recursiveparameter is set to True- Parameters:
path (
str) – The path of the directoryrecursive (
boolean) – Remove recursive
- Returns:
True if removal was successful
- Return type:
bool
- file.rmdir_r(path):
Remove a directory recursively.
- Parameters:
path (
str) – The path of the directory- Returns:
True if removal was successful
- Return type:
bool
- file.save(data, target_path, **kwargs):
save text data to a local file
- Parameters:
data (str) – Data which should be written to a file
target_path (str) – path to the new file
- Returns:
Returns True on success, False on Failure
- Return type:
bool
- Keyword Arguments:
overwrite (
bool) – Should a existing file be overwritten?, defaults to True
- file.strip_suffix(filename):
Strip the suffix from the filename /some/path/my.file –> /some/path/my
- Parameters:
filename (
str) – The filename- Returns:
Filename without suffix
- Return type:
str