Posted By

iloveitaly on 07/24/09


Tagged

copy create add extension keep suffix retain


Versions (?)

Add Suffix, Retain Extension, and Copy


 / Published in: Bash
 

  1. #!/bin/bash
  2.  
  3. SOURCE_DIR="~/Desktop/in"
  4. SOURCE_DIR_NAME=`basename "$SOURCE_DIR"`
  5. SUFFIX="_l"
  6. TARGET_DIR="~/Desktop/out"
  7.  
  8. find "$SOURCE_DIR" | while read file; do
  9. baseName=`basename "$file"`
  10.  
  11. if [[ ${baseName:0:1} == "." || "$baseName" == "$SOURCE_DIR_NAME" ]]; then
  12. continue
  13. fi
  14.  
  15. NAME=`echo "$baseName" | cut -d'.' -f1`
  16. EXTENSION=`echo "$baseName" | cut -d'.' -f2`
  17.  
  18. cp "$file" "$TARGET_DIR/$NAME$SUFFIX.$EXTENSION"
  19. done
  20.  
  21. exit 0

Report this snippet  

You need to login to post a comment.