diff --git a/readme.md b/readme.md index 53c4ef4a3b7073d4900f291d82c103d54ac774fb..a96c5aca6777eb6959001946069dc39b897e78d6 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 6ea0b08f098266881c6c413949c44716dc3532be..13435e8147c1d0f31303d4337edf02f9f9bc1e9b 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} ]]