3

How can I loop through each directory recursively and whenever it finds a folder called VIDEO_TS, let Genisoimage convert that folder's content to an dvd-video iso image, the name of the iso would be the parent folder's name.

The command that I use for a single directory:

genisoimage -o movie_1.iso -dvd-video /shares/media/movies/Movie 1

And this is the script I got:

#!/bin/bash
parent_path=""
full_path=""

for file in $(find /shares/media/ -type d -name 'VIDEO_TS')
do

parent_path="$(dirname -- "$file")"
full_path="$file"

done

So I got the parent path and the full path to the VIDEO_TS directory.

parent_path="/shares/media/Movie One/"
full_path="/shares/media/Movie One/VIDEO_TS/"

How can I get only the Movie One from parent_path? And when I use sprintf to echo both variables, either spaces get removed or replaced with a line break. Is it safe to use those variables with the command?

1
  • 1
    Don't use for with the output of find. Either do find ... | while read -r file ... or while read -r file ... done < <(find ...) Commented Nov 28, 2013 at 20:58

1 Answer 1

4

The command you are looking for is basename:

[root@localhost ~] # basename "/shares/media/Movie One/"
Movie One
[root@localhost ~] #
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .