better directory name extraction