How to check if all directories of file's path exists?

I wonder if the script below is possible to write somehow more efficiently. It seems to me the problem is very common..

CreateFolders() # parameter: name of file with relative path with regard to directory $project_root
{
echo $1 | awk '{ n=split($1, array, "/");
for (i=1;i<n;i++) {
print array
[i]}
} ' >"$project_root/createDirectory.tmp"

if [ -s "$project_root/createDirectory.tmp" ]; then

  folder=$project_root

  while read subdir; do
          
    if [ ! -d "$folder/$subdir" ];then        
      mkdir "$folder/$subdir"        
    fi
  
    cd "$folder/$subdir"
    
    folder="$folder/$subdir"
  
  done&lt;"$project_root/createDirectory.tmp"

fi

rm "$project_root/createDirectory.tmp";      

}

Thank you for help

I'm not sure I understand what you exactly are trying to do.
You can use mkdir -p <directory tree> to create the whole tree in one go
e.g.:
folder=${project_root}/local/pub/etc
mkdir -p $folder

thanks you! it's pretty faster way :slight_smile: