ladybug.futil module¶
Utility functions for working with files and directories.
- ladybug.futil.copy_file_tree(source_folder, dest_folder, overwrite=True)[source]¶
Copy an entire file tree from a source_folder to a dest_folder.
- Parameters:
source_folder – The source folder containing the files and folders to be copied.
dest_folder – The destination folder into which all the files and folders of the source_folder will be copied.
overwrite – Boolean to note whether an existing folder with the same name as the source_folder in the dest_folder directory should be overwritten. Default: True.
- ladybug.futil.copy_files_to_folder(files, target_folder, overwrite=True)[source]¶
Copy a list of files to a new target folder.
- Parameters:
files – A list of file paths to be copied to the target_folder.
target_folder – File path to a folder where the files will be copied to.
overwrite – Boolean to note whether an existing file with the same name as one of the files in the target_folder should be overwritten. Default: True.
- Returns:
A list of full paths to the new files.
- ladybug.futil.csv_to_matrix(csv_file_path)[source]¶
Load a CSV file into a Python matrix of strings.
- Parameters:
csv_file_path – Full path to a valid CSV file (e.g. c:/ladybug/test.csv)
- ladybug.futil.csv_to_num_matrix(csv_file_path)[source]¶
Load a CSV file consisting only of numbers into a Python matrix of floats.
- Parameters:
csv_file_path – Full path to a valid CSV file (e.g. c:/ladybug/test.csv)
- ladybug.futil.download_file(url, file_path, mkdir=False)[source]¶
Write a string of data to file.
- Parameters:
url – A string to a valid URL.
file_path – Full path to intended download location (e.g. c:/ladybug/testPts.pts)
mkdir – Set to True to create the directory if doesn’t exist (Default: False)
- ladybug.futil.download_file_by_name(url, target_folder, file_name, mkdir=False)[source]¶
Download a file to a directory.
- Parameters:
url – A string to a valid URL.
target_folder – Target folder for download (e.g. c:/ladybug)
file_name – File name (e.g. testPts.zip).
mkdir – Set to True to create the directory if doesn’t exist (Default: False)
- ladybug.futil.nukedir(target_dir, rmdir=False)[source]¶
Delete all the files inside target_dir.
- Parameters:
target_dir – Target folder to be deleted (e.g. c:/ladybug/libs).
rmdir – Boolean to note whether the target_dir itself should be deleted. If False, only the files within the target_dir will be deleted. Default: False.
Usage:
nukedir("c:/ladybug/libs", True)
- ladybug.futil.preparedir(target_dir, remove_content=True)[source]¶
Prepare a folder for files to be written into it.
This function creates the folder if it does not exist and removes the files in the folder if the folder already exists.
- Parameters:
target_dir – Target folder into which files will be written (e.g. c:/ladybug/libs).
remove_content – Boolean to note whether any existing content within the target_dir should be deleted. If False, only the directory creation will happen if the target_dir does not exist (nothing will be deleted). Default: True.
- ladybug.futil.unzip_file(source_file, dest_dir=None, mkdir=False)[source]¶
Unzip a compressed file.
- Parameters:
source_file – Full path to a valid compressed file (e.g. c:/ladybug/testPts.zip)
dest_dir – Target folder to extract to (e.g. c:/ladybug). Default is set to the same directory as the source file.
mkdir – Set to True to create the directory if doesn’t exist (Default: False)
- ladybug.futil.write_to_file(file_path, data, mkdir=False)[source]¶
Write a string of data to file.
- Parameters:
file_path – Full path for a valid file path (e.g. c:/ladybug/testPts.pts)
data – Any data as string
mkdir – Set to True to create the directory if doesn’t exist (Default: False)
- ladybug.futil.write_to_file_by_name(folder, fname, data, mkdir=False)[source]¶
Write a string of data to file by filename and folder.
- Parameters:
folder – Target folder (e.g. c:/ladybug).
fname – File name (e.g. testPts.pts).
data – Any data as string.
mkdir – Set to True to create the directory if doesn’t exist (Default: False).