Did you tested it? I would assume that $view->opendir() needs to get the path relative to the views root dir. So most likely you need to use $dir here.