0

I am currently working on a script, that shall set the titles of all found MKV/MKA/MKS files to their basename for example:

/path/to/the/file/this is a cool title.mkv

Should be automatically edited with mkvpropedit and the title shall be set to "this is a cool title".

I can ATM set the title to a static value, but as the title should always be the filename (without extension) it somehow does not work.

My script is as following:

find . -iname "*.mk*" -type f -exec mkvpropedit -e info --set title="$(basename)" {} \;

It runs "find", then -exec on every found entry and set the title to the found entrys "basename". At least thats how it should work. But basename does not work since it does not know what it should create a basename from.

Is there a way to pass the path to a subcommand in a -exec command?

Martin
  • 208
  • 4
  • 15

1 Answers1

1

You can do this sort of thing by passing the filename to sh:

find . -iname "*.mk*" -type f -exec sh -c 'mkvpropedit -e info --set title="$(basename "$1")" "$1"' _ {} \;
William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • Thanks! I tried it, but it fails. I guess because of whitespaces in the filename. Tried with a filename like this: "Cool Series S01E03 - some title.mkv" – Martin Feb 21 '22 at 14:19
  • @Martin The original answer was underquoted. Add double quotes around `$1` – William Pursell Feb 21 '22 at 14:24
  • still not working as basename now reports, that not filepath was provided. – Martin Feb 21 '22 at 14:28
  • 1
    `title="$(basename "$1")" "$1"' _ {}` – KamilCuk Feb 21 '22 at 14:41
  • Thanks @KamilCuk that did the trick. It includes the fileextension, but I went around this by adding it to: `title="$(basename "$1" "mkv")" "$1"' _ {}` even tho I would also like to remove "mka" and "mks" case-insensitive. – Martin Feb 21 '22 at 16:19