Start New Discussion Reply to this Discussion File Renaming & Folder Sorting
Hi,
I am trying to write a Bash Script to sort some images but I am new to Bash and not having any luck.
I have a folder of images.
Example:
P100.jpg
P172.jpg
P342.jpg
P400.png
I need to change these filenames to <filename>_DEFAULT<extension>.
ie. P100_DEFAULT.jpg and then move the file into a folder with the name of the original file.
Pseudo:
Load file list for directory
For each file in the directory:
{
filename = <filename>
newfilename = <filename>_DEFAULT<extension>
mkdir <filename> #if directory doesn't exist
mv <filename> <newdir/newfilename>
}
NOTE: I will be running the script on MacOSX (BASH 3.2)
Any help will be appreciated.
Related Article: File Renaming & Folder Sorting
is a Shell Scripting discussion thread by John Linux that has 2 replies, was last updated 1 year ago and has been tagged with the keywords: file, rename, bash, mac, osx.
John Linux
Light Poster
29 posts since May 2010
Reputation Points: 30
Solved Threads: 0
Skill Endorsements: 0
for FILE in *; do
NEWFILE="${FILE%.*}_DEFAULT.${FILE##*.}"
mv "$FILE" "$NEWFILE"
mkdir -p "$FILE"
mv "$NEWFILE" "$FILE"
done
KenJackson
Newbie Poster
13 posts since Apr 2010
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
© 2013 DaniWeb® LLC
Page rendered in 0.0575 seconds
using 2.66MB