×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
1
Language: Bash
Posted by: Jackomo Light
Added: Feb 2, 2013 4:51 PM
Views: 1769
Tags: sorting
  1. cd /path/to/dir
  2.  
  3. shopt -s nullglob
  4. for file in *.{avi,rmvb,mkv}
  5. do
  6.   directory="${file%.*}"             # remove file extension
  7.   directory="${directory//_/ }"      # replace underscores with spaces
  8.  
  9.   darr=( $directory )
  10.   darr="${darr[@]^}"                 # capitalize the directory name
  11.  
  12.   echo mkdir -p -- "$darr"           # create the directory;
  13.   echo mv -b -- "$file" "$darr"      # move the file to the directory
  14.   echo
  15. done