Function sortery::tools::sort::get_sorting_results[][src]

fn get_sorting_results(
    source: &File,
    target: &File,
    date_format: &str,
    date_type: &str,
    preserve_name: &bool,
    exclude_type: (&str, bool),
    only_type: (&str, bool)
) -> (usize, Vec<File>, Vec<File>)
Expand description

The main sorting algorithm; this checks files for validity and shows the progress bar.

The parameters are as follows:

  • source is the directory from which to get all the files to sort.

  • target is the directory into which to sort all the files.

  • date_format is the date format with which to rename the files. It shares the formatting rules with the chrono::format::strftime module.

  • date_type is the date to sort the files by; one of "c" (created), "a" (accessed), or "m" modified. Note that creation time is not available on all filesystems.

  • preserve_name, if set to true, will add the original filename after the date, separated by a space. For example, sorting a file test.txt with preserve_name=true will rename test.txt to 2021-04-21 06h34m02s test.txt

  • exclude_type is a tuple containing two items. One is a str representing the extension of a file type to exclude from sorting. For example, if "jpg" is passed, all files ending in .jpg will be ignored during sorting. The other item is a bool telling whether exclude_type should take effect or not.

  • only_type is tuple containing two items. One is a str representing the extension of a file type to exclusively sort. For example, if "jpg" is passed, only files ending in .jpg will be sorted; all others will be ignored. Overrides the exclude_type option. The other item is a bool telling whether only_type shoud take effect or not.

This returns a three-item tuple containing: a usize representing the number of items to be sorted, a Vec<File> of the old file names, and a Vec<File> of the new file names. Each item in the old file names corresponds with the item of the same index in the new file names. So old_names[0] will be renamed to new_names[0], old_names[1] will be renamed to new_names[1], etc.