Add Suffix, Retain Extension, and Copy


/ Published in: Bash
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.