diff --git a/readme.md b/readme.md index a96c5aca6777eb6959001946069dc39b897e78d6..17981b6b593182866ab166fc9a9b97f6ce32b799 100644 --- a/readme.md +++ b/readme.md @@ -14,5 +14,6 @@ Organizes files by type. * Second arg (required) - Expected to be the output directory. ### Flags +* `-b` - Appropriately renames files with known "bad" file name prefixes and file extensions. * `-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 51e36ce45db4161725f354d5520d547d73470ade..ba6e1306bb06986965efb84cd5b919fe3e951420 100755 --- a/run.sh +++ b/run.sh @@ -52,9 +52,6 @@ function main () { exit 1 fi - echo "input_dir: ${input_dir}" - echo "output_dir: ${output_dir}" - # Validate passed args. if [[ "${flags[@]}" =~ "no-sort" && "${input_dir}" == "${output_dir}" ]] then @@ -89,17 +86,23 @@ function main () { # Determines full directory location (based on file type) and then calls move_file() function. ## function handle_file () { - local file=${1} - if [[ "${file_extension}" == "" ]] then # First, non-recursive entry into function. - parse_file_name ${file} + parse_file_name ${1} + orig_file_location="${file_name}${file_extension}" to_lower ${file_extension} file_extension=${return_value} fi + # Check for flag. + if [[ "${flags[@]}" =~ "b" ]] + then + # Handle for known "bad" file name values. + handle_bad_file_names + fi + # Handle based on found extension. # Handle images. if [[ "${file_extension}" == ".jpg" || @@ -353,6 +356,26 @@ function handle_file () { } +### + # Handles for known "bad" file name values. + # Includes known "bad" name prefixes and "bad" file extensions. + ## +function handle_bad_file_names () { + + # Handle for discord spoiler prefix. + if [[ "${file_name}" == "SPOILER_"* ]] + then + file_name=${file_name#SPOILER_} + fi + + # Handle for silly jpg file extension. + if [[ "${file_extension}" == ".jpg_large.jpg" ]] + then + file_extension=".jpg" + fi +} + + ### # Handles physically moving file between locations. # Includes handling for if file with identical name already exists in output directory. @@ -379,7 +402,7 @@ function move_file () { done fi - local input_location="${input_dir}/${orig_file_name}${file_extension}" + local input_location="${input_dir}/${orig_file_location}" local output_location="${output_subdir}/${file_name}${file_extension}" echo -e "Moving ${text_purple}${orig_file_name}${file_extension}${text_reset} to ${text_purple}${output_location}${text_reset}"