From 72aefa6ebb89dfc30e382ec4f9132cc3cb62e7bd Mon Sep 17 00:00:00 2001 From: Brandon Rodriguez <brodriguez8774@gmail.com> Date: Mon, 12 Oct 2020 01:06:31 -0400 Subject: [PATCH] Add "no sort" option --- readme.md | 1 + run.sh | 101 ++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 92 insertions(+), 10 deletions(-) diff --git a/readme.md b/readme.md index 53c4ef4..a96c5ac 100644 --- a/readme.md +++ b/readme.md @@ -15,3 +15,4 @@ Organizes files by type. ### Flags * `-no-exe` - Skips handling of windows exe files. +* `-no-sort` - Skips sorting of files into labelled subdirectories. diff --git a/run.sh b/run.sh index 6ea0b08..13435e8 100755 --- a/run.sh +++ b/run.sh @@ -96,7 +96,15 @@ function handle_file () { "${file_extension}" == ".jpeg" || "${file_extension}" == ".png" ]] then - output_subdir="${output_dir}/Images" + # Check for sorting flag. + if [[ "${flags[@]}" =~ "no-sort" ]] + then + # Sorting disabled. + output_subdir="${output_dir}" + else + # Sorting enabled. + output_subdir="${output_dir}/Images" + fi # Verify location exists. if [[ ! -d ${output_subdir} ]] @@ -111,7 +119,15 @@ function handle_file () { # Handle animated images/video. elif [[ "${file_extension}" == ".gif" ]] then - output_subdir="${output_dir}/GIFs" + # Check for sorting flag. + if [[ "${flags[@]}" =~ "no-sort" ]] + then + # Sorting disabled. + output_subdir="${output_dir}" + else + # Sorting enabled. + output_subdir="${output_dir}/GIFs" + fi # Verify location exists. if [[ ! -d ${output_subdir} ]] @@ -124,7 +140,15 @@ function handle_file () { elif [[ "${file_extension}" == ".mp4" ]] then - output_subdir="${output_dir}/MP4s" + # Check for sorting flag. + if [[ "${flags[@]}" =~ "no-sort" ]] + then + # Sorting disabled. + output_subdir="${output_dir}" + else + # Sorting enabled. + output_subdir="${output_dir}/MP4s" + fi # Verify location exists. if [[ ! -d ${output_subdir} ]] @@ -140,7 +164,15 @@ function handle_file () { elif [[ "${file_extension}" == ".flv" || "${file_extension}" == ".swf" ]] then - output_subdir="${output_dir}/Flash" + # Check for sorting flag. + if [[ "${flags[@]}" =~ "no-sort" ]] + then + # Sorting disabled. + output_subdir="${output_dir}" + else + # Sorting enabled. + output_subdir="${output_dir}/Flash" + fi # Verify location exists. if [[ ! -d ${output_subdir} ]] @@ -156,7 +188,15 @@ function handle_file () { elif [[ "${file_extension}" == ".doc" || "${file_extension}" == ".docx" ]] then - output_subdir="${output_dir}/Word" + # Check for sorting flag. + if [[ "${flags[@]}" =~ "no-sort" ]] + then + # Sorting disabled. + output_subdir="${output_dir}" + else + # Sorting enabled. + output_subdir="${output_dir}/Word" + fi # Verify location exists. if [[ ! -d ${output_subdir} ]] @@ -169,7 +209,15 @@ function handle_file () { elif [[ "${file_extension}" == ".pdf" ]] then - output_subdir="${output_dir}/PDFs" + # Check for sorting flag. + if [[ "${flags[@]}" =~ "no-sort" ]] + then + # Sorting disabled. + output_subdir="${output_dir}" + else + # Sorting enabled. + output_subdir="${output_dir}/PDFs" + fi # Verify location exists. if [[ ! -d ${output_subdir} ]] @@ -182,7 +230,15 @@ function handle_file () { elif [[ "${file_extension}" == ".ppt" ]] then - output_subdir="${output_dir}/PowerPoints" + # Check for sorting flag. + if [[ "${flags[@]}" =~ "no-sort" ]] + then + # Sorting disabled. + output_subdir="${output_dir}" + else + # Sorting enabled. + output_subdir="${output_dir}/PowerPoints" + fi # Verify location exists. if [[ ! -d ${output_subdir} ]] @@ -196,7 +252,15 @@ function handle_file () { elif [[ "${file_extension}" == ".xls" || "${file_extension}" == ".xlsx" ]] then - output_subdir="${output_dir}/Spreadsheets" + # Check for sorting flag. + if [[ "${flags[@]}" =~ "no-sort" ]] + then + # Sorting disabled. + output_subdir="${output_dir}" + else + # Sorting enabled. + output_subdir="${output_dir}/Spreadsheets" + fi # Verify location exists. if [[ ! -d ${output_subdir} ]] @@ -214,7 +278,15 @@ function handle_file () { # Only proceed if flags aren't set. if [[ ! "${flags[@]}" =~ "no-exe" ]] then - output_subdir="${output_dir}/Executables" + # Check for sorting flag. + if [[ "${flags[@]}" =~ "no-sort" ]] + then + # Sorting disabled. + output_subdir="${output_dir}" + else + # Sorting enabled. + output_subdir="${output_dir}/Executables" + fi # Verify location exists. if [[ ! -d ${output_subdir} ]] @@ -242,7 +314,16 @@ function handle_file () { handle_file ${file_name} ${file_extension} else # Extension is already smallest possible format. Unknown file extension. - output_subdir="${output_dir}/Other" + + # Check for sorting flag. + if [[ "${flags[@]}" =~ "no-sort" ]] + then + # Sorting disabled. + output_subdir="${output_dir}" + else + # Sorting enabled. + output_subdir="${output_dir}/Other" + fi # Verify location exists. if [[ ! -d ${output_subdir} ]] -- GitLab