Crate brown[][src]

Enums

Functions

The clone_dir_structure takes a source folder and destination folder names. It will then create a destination folder and clone the source folder/directory structure in to that.

The create_dir function will create a folder safely i.e in case the folder does not exist, it will be created But incase the folder already exists the function will return an error.

The create_dir_all is just like brown::create_dir except it Recursively create a directory and all of its parent components if they are missing.

The create_dir_brute fn is for times when you want to create a directory without worring about if that directory already existed or not. If the folder already exists it will return true, if the folder does NOT exist it will create it and then return true. Error is returned only when the operating system call for creating folder fails. This function is more concerned about creating the folder and less about saving the contents of the folder. This makes it a better candidate for creating setup folders etc. If a path with non existing top level folders is given to create_dir_brute; those missing folders will also be created.

The create_dir_structure will take a &Vec of String (paths) ususally provided by dir_structure_to_string and create a folder structure using that.

This function will create a file at a given path as long as the file does not exist already. In case the file aready exists it will return an error and will not over write the file. Its operation is safe.

The create_file_brute function is not safe. It means that it will create a new file even if an old one exists. If this is not what you want you should try create_file.

The dir_structure_to_string will convert all the paths of a folder into a vec of strings.

The direntry_to_path fn will take a Rust DirEntry type and return its path as string. This saves us 12 lines of code and 3 conversions.

This fn will take a Rust a Vec of &DirEntry type and return all of its paths as string. If we set its “strict” flag to false then it will ignore the errors and return as many paths as it can. Incase the “strict” flag is set to true then in will return error even if a single DirEntry fails to return path.

The get_dirs will get all the directories from a directory leaving out the files. It will return error if no directory is found thus the user does not have to check if the returned vec has some values or not.
Note:: This function will dig in just one level. It will not look for sub-sub folders. Do not include the “./” before the dir_path

This fn takes a Vec of DirEntries and will return all the sub-directories of all the provided DirEntries. It is used to get sub-folder of a directory at any given level by providing all the parent folders. This function is helpful for traversing a directory structure.

The get_entries fn will get all the entries from a directory may it be files , folders or others. If there is no entry in the said direcotry i.e there is no file or folder etc, in that case it will return an error. This will save the user from checking every time the returned vec if it has entries or not. It returns a Vec of DirEntry when successful. The DirEntry is a Rust struct used for holding any entry in a directory. The dir_path should not have “./” since that will be added automatically.

The get_ext function will take a DirEntry object and return the file extention. This saves us a lot of efforts and conversion between types.

The get_file_name takes a DirEntry and return its file name with out the extentions.

The get_files will get all the files from a folder leaving out the directories. It will return error if no file is found thus the user does not have to check if the returned vec has some values or not.

The get_files_by_ext is just like get_files but it get files based on their extention. If no file is found with the given extention an error is returned.

The get_read_dir will return “ReadDir” struct from Rust which is a iterator over the directory

We can directly get is_dir function using DirEntry. However this saves us digging down two levels.

The is_file function takes in Rust Struct &DirEntry and return if that &DirEntry is a file or a folder. It is for ease of use and to save us duplicate code.

The Rust std::fs::DirEntry path object has “exists” however this function takes a &str and converts that into path thus is useful when the DirEntry object has not been obtained.

The remove_dir funtion will remove a directory only if its empty. Its operation is safe. This fn should be used always unless brute removal is required Example ::

The remove_dir_brute fn will delete a folder even if it has other files and folders. USE WITH CAUTION!!. This fn is used to ensure that a folder does not exist.If the folder does not exist ALREADY it will still return true since the purpose of removing the folder is achieved. Example ::

The remove_file method will delete the file on the given path. It is a wrapper around fs::remove_file

This function will create a file if it does not exist, and will entirely replace its contents if it does.