0

I want to rename files in a dir then change the file name base on the dir name this is what I had but it's not quite working

    find . -type d | while read dir
do
  cd "$dir"
  find . -name \*.rar -exec unrar x '{}' \;
  find . -name \*.avi -exec mv '{}' "$dir.avi" \;
  cd ..
done

root/directory.1.with.rar.in/

root/directory.2.with.rar.in/

root/directory.2.with.rar.in/

root/directory.2.with.rar.in/

root/directory.2.with.rar.in/

I want all the rar in the Directory to be extracted in root then renamed with the name of the directory it was extracted from.

akjoshi
  • 15,374
  • 13
  • 103
  • 121
  • could you check the filenames are not ending with .rar rather they are ending with .rar.in – Shiva Komuravelly Jan 03 '13 at 06:42
  • 1
    It looks to me like you're basically there, except that the 'mv' statement is executed in the directory $dir; If I'm reading your request correctly, you need to use `find . -name \*.avi -exec mv '{}' "../$dir.avi" \;` instead of `find . -name \*.avi -exec mv '{}' "$dir.avi" \;`. I haven't worked much with rar files; I don't remember if they're capable of containing more than a single file. If so, you will overwrite the first avi file when you move the second. – Barton Chittenden Jan 03 '13 at 07:10

0 Answers0