Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.08 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. OUTPUT_PATH="./output/"
  4. INPUT_PATH="./input/"
  5. FORCE=false
  6.  
  7. function show_help
  8. {
  9.     echo "Usage:"
  10.     echo "  -h - show help:"
  11.     echo "  -i path - set input path (default='./')"
  12.     echo "  -o path - set output path (default='./')"
  13.     echo "  -f - force move - removes name-colliding files from output folder"
  14. }
  15.  
  16. while getopts "fhi:o:" opt; do
  17.     case "$opt" in
  18.     h|\?)
  19.         show_help
  20.         exit 0
  21.         ;;
  22.     i)  INPUT_PATH=$OPTARG
  23.         ;;
  24.     o)  OUTPUT_PATH=$OPTARG
  25.         if [[ ! -d $OUTPUT_PATH ]]; then
  26.             echo "ERROR: Specified output path is not a directory"
  27.             exit 1
  28.         fi
  29.         ;;
  30.     f) FORCE=true
  31.        
  32.         ;;
  33.     esac
  34. done
  35.  
  36.  
  37. if [[ ! -d $INPUT_PATH ]]; then
  38.     echo "ERROR: Specified input path is not a directory"
  39.     exit 1
  40. fi
  41.  
  42. mkdir -p $OUTPUT_PATH
  43.  
  44. I=$((-1))
  45.  
  46. for f in $INPUT_PATH/*
  47. do
  48.     I=$((I+1))
  49.     if [[ -e $OUTPUT_PATH/$I ]]; then
  50.         if [ $FORCE == true ]; then
  51.         echo F
  52.         rm -rf $OUTPUT_PATH/$I
  53.       else
  54.         echo NF
  55.         continue
  56.       fi
  57.     fi
  58.     mv $f $OUTPUT_PATH/$I
  59. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement