look for a child folder of the parent folder, if not found, create it and return it.
503892
private static Folder getOrCreateFolder(final Folder parentFolder, final String folderName)  throws IOException {
        Folder childFolder = null;

        // get existing if any
        ItemIterable<CmisObject> children = parentFolder.getChildren();
        if (children.iterator().hasNext()) {
            for (CmisObject cmisObject : children) {
                if (cmisObject instanceof Folder && cmisObject.getName().equals(folderName)) {

                    log.debug("Found '{}' folder.", folderName);

                    return childFolder = (Folder)cmisObject;
                }
            }
        }

        // Create new folder (requires at least type id and name of the folder)
        log.debug("'{}' folder not found, about to create...", folderName);

        Map<String, String> folderProps = new HashMap<String, String>();
        folderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
        folderProps.put(PropertyIds.NAME, folderName);

        childFolder = parentFolder.createFolder(folderProps);

        log.info("'{}' folder created!", folderName);

        return childFolder;
    }
163188
def get_child_directories(path):
    """"""
    if not _is_valid_directory(path):
        raise exceptions.InvalidDirectory

    entries = os.listdir(path)
    directory_names = []

    for entry in entries:
        abs_entry_path = os.path.join(path, entry)
        if _is_valid_directory(abs_entry_path):
            directory_names.append(entry)

    return directory_names
1017950
def glob_in_parents(dir, patterns, upper_limit=None):
    """"""

    assert(isinstance(dir, str))
    assert(isinstance(patterns, list))

    result = []

    absolute_dir = os.path.join(os.getcwd(), dir)
    absolute_dir = os.path.normpath(absolute_dir)
    while absolute_dir:
        new_dir = os.path.split(absolute_dir)[0]
        if new_dir == absolute_dir:
            break
        result = glob([new_dir], patterns)
        if result:
            break
        absolute_dir = new_dir

    return result
798569
private File newSubdirectory(File parentDirectory, String path) {
        File dir = new File(parentDirectory, path);

        if (!dir.exists()) {
            dir.mkdirs();
        }

        return dir;
    }
649126
def get_folder(self, si, path, root=None):
        

        search_index = si.content.searchIndex
        sub_folder = root if root else si.content.rootFolder

        if not path:
            return sub_folder

        paths = [p for p in path.split("/") if p]

        child = None
        try:
            new_root = search_index.FindChild(sub_folder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)
        except:
            child = None

        if child is None and hasattr(sub_folder, self.ChildEntity):
            new_root = search_index.FindChild(sub_folder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        if child is None and hasattr(sub_folder, self.VM):
            new_root = search_index.FindChild(sub_folder.vmFolder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        if child is None and hasattr(sub_folder, self.Datastore):
            new_root = search_index.FindChild(sub_folder.datastoreFolder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        if child is None and hasattr(sub_folder, self.Network):
            new_root = search_index.FindChild(sub_folder.networkFolder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        if child is None and hasattr(sub_folder, self.Host):
            new_root = search_index.FindChild(sub_folder.hostFolder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        if child is None and hasattr(sub_folder, self.Datacenter):
            new_root = search_index.FindChild(sub_folder.datacenterFolder, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        if child is None and hasattr(sub_folder, 'resourcePool'):
            new_root = search_index.FindChild(sub_folder.resourcePool, paths[0])
            if new_root:
                child = self.get_folder(si, '/'.join(paths[1:]), new_root)

        return child
697188
def find(self, name, limit=None):
        """"""
        if name == self.name:
            if limit is not None:
                assert limit == 1
                self.subdirs = []
            return self
        for subdir in self.subdirs:
            res = subdir.find(name, limit)
            if res is not None:
                return res
        return None
829106
function mkdirIf(dir, parent) {
	var path = parent ? parent : ".";
	if (getDirectories(path).indexOf(dir) == -1) fs.mkdirSync(path + "/" + dir);
}
672066
def _create_target_dir_if_needed(self, target, depth_limit=20):
        """"""

        if depth_limit <= 0:
            raise FtpCreateDirsException('Depth limit exceeded')
        if not target:
            return
        target_dir = os.path.dirname(target)
        parent_dir, dir_name = os.path.split(target_dir)

        parent_dir_ls = []
        try:
            parent_dir_ls = self.ftp.nlst(parent_dir)
        except:
            # Possibly a microsoft server
            # They throw exceptions when we try to ls non-existing folders
            pass

        parent_dir_files = [os.path.basename(d) for d in parent_dir_ls]
        if dir_name not in parent_dir_files:
            if parent_dir and target_dir != '/':
                self._create_target_dir_if_needed(target_dir, depth_limit=depth_limit - 1)

            self.logger.info('Will create dir: %s' % target)
            self.ftp.mkd(target_dir)
318442
def _fetch_parent_path(self, request: Request, use_cache: bool=True):
        '''
        '''
        directory_url = to_dir_path_url(request.url_info)

        if use_cache:
            if directory_url in self._processor.listing_cache:
                return self._processor.listing_cache[directory_url]

        directory_request = copy.deepcopy(request)
        directory_request.url = directory_url

        _logger.debug('Check if URL {} is file with {}.', request.url,
                      directory_url)

        with self._processor.ftp_client.session() as session:
            try:
                yield from session.start_listing(directory_request)
            except FTPServerError:
                _logger.debug('Got an error. Assume is file.')

                if use_cache:
                    self._processor.listing_cache[directory_url] = None

                return

            temp_file = tempfile.NamedTemporaryFile(
                dir=self._item_session.app_session.root_path,
                prefix='tmp-wpull-list'
            )

            with temp_file as file:
                directory_response = yield from session.download_listing(
                    file, duration_timeout=self._fetch_rule.duration_timeout)

        if use_cache:
            self._processor.listing_cache[directory_url] = \
                directory_response.files

        return directory_response.files
1303129
def parent_dir(path):
    ''''''
    return os.path.abspath(os.path.join(path, os.pardir, os.pardir, '_build'))
244310
function(parentLocation, folderName) {
			var that = this;
			return this._getEntry(parentLocation).then(function(dirEntry) {
				var d = new orion.Deferred();
				dirEntry.getDirectory(folderName, {create:true}, function() {d.resolve(that.read(parentLocation + "/" + folderName, true));}, d.reject);
				return d;
			});
		}
917641
function createParentPath(client, path, callback) {
  var parentDir = path.substring(0, path.lastIndexOf('/'));

  debug('createParentPath: "%s"', parentDir);

  if (parentDir.length != 0) {
    client.create(parentDir, function(err) {
      if (err) {
        if (err.code === NO_NODE) {
          return createParentPath(client, parentDir, function(err) {
            if (err) return callback(err);

            createParentPath(client, path, callback);
          });
        } else if (err.code !== NODE_EXISTS)
          return callback(err);
      }
      callback(null, path);
    });
  } else
    callback(null, path);
}
108803
private void createFolder(final StructrShellCommand parent, final Folder currentFolder, final String target) throws FrameworkException, IOException {

		final App app = StructrApp.getInstance();
		if (target.contains("/")) {

			final int lastSlashIndex      = target.lastIndexOf("/");
			final String targetFolderPath = target.substring(0, lastSlashIndex);
			final String targetFolderName = target.substring(lastSlashIndex + 1);
			final Folder parentFolder     = parent.findRelativeFolder(currentFolder, targetFolderPath);

			if (parentFolder != null) {

				checkAndCreateFolder(app, parent, parentFolder, targetFolderName);

			} else {

				term.println("Folder " + targetFolderPath + " does not exist");
			}

		} else {

			checkAndCreateFolder(app, parent, currentFolder, target);
		}
	}
858966
public static LocalDocument findLocalDocumentByParentAndUrlName(Folder parentFolder, String urlName) {
    ResourceDAO resourceDAO = new ResourceDAO();
    
    Resource resource = resourceDAO.findByUrlNameAndParentFolder(urlName, parentFolder);
    if (resource instanceof LocalDocument) {
      return (LocalDocument) resource;
    }
    
    return null;
  }
133554
def create_parent_folder(filename):
    
    path = os.path.dirname(filename)
    if path != '':
        make_folder(path)
48865
private function searchInPath(FileSystem\Iterator\IteratorAggregate $iterator, $path, FileSystem\Directory $parent = null, $depth = 0)
    {
        // when exists.
        if (file_exists($path)) {
            if(is_dir($path)) {
                $dir = new FileSystem\Directory($path);
                if ($parent) $dir->setParent($parent);
                if ($this->validate($dir)) $iterator->add($dir);
                if ($this->recursive || $depth < 1) {
                    $this->searchInPath($iterator, "{$dir}/*", $dir, $depth + 1);
                }
            } else {
                $file = new FileSystem\File($path);
                if ($parent) $file->setParent($parent);
                if ($this->validate($file)) $iterator->add($file);
            }
        }
        // when not exists, then glob.
        else {
            foreach (glob($path) as $file) {
                $this->searchInPath($iterator, $file, $parent, $depth);
            }
        }
    }
646215
def create_directory(directory):
    """"""
    if os.path.exists(directory):
        rmtree(directory)
    os.makedirs(directory)
    return directory