Crate brown[][src]

Modules

Statics

Functions

The creation of a directory is always a safe operation i.e in case the folder already exists it will return an error. Example :: ``` let p_dir = brown::create_dir(“parent”); assert!(p_dir.is_ok());

This function will create a file at 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. You need to give a complete file path : i.e file path + file name + extention. However you do not need to add “./” before the path, that will be added automatically. Example :: let x = hdir.create_file(“parent_folder/child_folder/file_name.md”); In case any folder in the given path is not found it will an return error.

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

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

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. Do not add “.” (the dot) with file extention Example:: “md” , “html” , “txt” etc Do not include the “./” before the dir_path

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. This saves us digging down two levels.

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 of its empty. Its operation is safe. This fn should be used normally unless brute removal is required Example :: ``` let p_dir = brown::create_dir(“parent”); let outcome = brown::remove_dir(“parent”); assert!(outcome.is_ok());

The remove_dir_brute fn will delete a folder even if it has other files and folders. USE WITH CAUTION!! Example :: ``` let p_dir = brown::create_dir(“parent”); let outcome = brown::remove_dir_brute(“parent”); assert!(outcome.is_ok());

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.