I have a mostly automated media server and currently have everything going into one folder and being sorted out by file extension into the correct locations.
At the moment the photos are coming in named "folder.jpg" and I need to rename them to match the movie name.
What it looks like now:
Before:
-
/Directory/
- folder.jpg
- Movie.mp4
- Movie.xml
What I need it to look like:
After:
-
/Directory/
- Movie.jpg
- Movie.mp4
- Movie.xml
How would I go about matching the jpg to mp4.
Best Answer
Try:
${movie%/*}
and${movie%.mp4}
are both examples of suffix removal.${movie%/*}
returns the directory that the movie file is in and${movie%.mp4}
returns the name of the movie file minus the extension.mp4
.Example
Consider three directories,
dir1
,dir2
, anddir3
, with the files:Now, run our command:
After running our command, the files are:
Multiple line version
For those who prefer their commands spread over multiple lines: