code: private List<Resource<?>> allDirectoriesOnPath(Resource<?> startingDir)
     {
        List<Resource<?>> result = new ArrayList<>();
  
        while (startingDir != null)
        {
           result.add(startingDir);
           startingDir = startingDir.getParent();
        }
  
        return result;
     }
docs: Returns all directories on path starting from given directory up to the root.