Tar extract a multiple directories

i extract it through script, is there any way to script or automate to tar extract a tarfiles in multiple directories at once?

Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

for dir in `ls -d /tarfiles/*/ | sed 's/.$//'`
do
rm -f $dir/*.tar
mv -f $dir*tgz* $dir/
gunzip $dir/*.tgz
#done


for f in `ls -l $dir/*.tar`
#f=`ls -l $dir/*.tar`
do
tar xvf  "$dir/$f"  -C $dir/

It's not immediately obvious from the script what the directory and file structure you are working with looks like. Based on the first line, it looks like you have a number of directories in /tarfiles , each directory can contain one of more tar files which you immediately delete.
Next, you are looking for tar gz files that are in the /tarfiles directory and are named after each subdirectory, and then moving them into that subdirectory, it looks like there could be more than one per directory.
Once all that's done, you are unzipping the tar gzs, and then untaring them.

If all that is true, then we can proceed.

Each of the files returned by your for loop will already have the right directory included in it, you are then prepending the directory name again. You'd end up with something like /tarfiles/abcd/abcd/abcd-foo.tar when you actually want /tarfiles/abcd/abcd-foo.tar - thus tar saying it can't find the file.

If that's indeed what's happening, just remove the $dir part of the input file being passed to tar.