Breaks a path to a directory into a (drive, list-of-folders) tuple

    :param directory:
    :return: a tuple consisting of the drive (if any) and an ordered list of
             folder names
165650
def get_path_components(directory):
    
    drive, dirs = os.path.splitdrive(directory)
    folders = []
    previous = ""
    while dirs != previous and dirs != "":
        previous = dirs
        dirs, folder = os.path.split(dirs)
        if folder != "":
            folders.append(folder)
    folders.reverse()
    return drive, folders
1081229
def _prepare_directory(directory_path: str) -> str:
    
    exp_num = get_exp_dir_num(directory_path)
    exp_num = exp_num + 1
    exp_dir = os.path.join(directory_path, str(exp_num))
    if not os.path.isdir(exp_dir):
        os.makedirs(exp_dir)
    return exp_dir
946394
def get_folders(path):
        
        folder_paths = []

        for item in os.listdir(path):
            folder_path = os.path.join(path, item)

            if os.path.isdir(folder_path):
                folder_paths.append(folder_path)

        return folder_paths
114083
def list_filepathes_with_predicate(path_dir, predicate):
    '''
    '''
    if not os.path.isdir(path_dir):
        raise ValueError("{} is not a directory".format(path_dir))
    contents = (os.path.join(path_dir, a) for a in os.listdir(path_dir))
    files = (c for c in contents if os.path.isfile(c))
    return [f for f in files if f.startswith(predicate)]
1253393
def chdir(self, dir, change_os_dir=0):
        
        curr=self._cwd
        try:
            if dir is not None:
                self._cwd = dir
                if change_os_dir:
                    os.chdir(dir.get_abspath())
        except OSError:
            self._cwd = curr
            raise
650301
def _folder_to_dict(self, path):
        
        res = {}
        for key in os.listdir(path):
            if key.startswith('.'):
                continue
            key_path = os.path.join(path, key)
            if os.path.isfile(key_path):
                val = open(key_path).read()
                key = key.split('.')[0]
                res[key] = val
            else:
                res[key] = self._folder_to_dict(key_path)
        return res
203816
def chdir(self, path):
        
        self.cwd = self._join_chunks(self._normalize_path(path))
1273699
def rmdir(self, paths):
        ''' 
        '''
        if not isinstance(paths, list):
            raise InvalidInputException("Paths should be a list")
        if not paths:
            raise InvalidInputException("rmdir: no path given")

        processor = lambda path, node: self._handle_rmdir(path, node)
        for item in self._find_items(paths, processor, include_toplevel=True):
            if item:
                yield item
1034216
def remove_dirs(self, directory):
        

        LOG.info('Removing directory [ %s ]', directory)
        local_files = self._drectory_local_files(directory=directory)
        for file_name in local_files:
            try:
                os.remove(file_name['local_object'])
            except OSError as exp:
                LOG.error(str(exp))

        # Build a list of all local directories
        directories = sorted(
            [i for i, _, _ in os.walk(directory)],
            reverse=True
        )

        # Remove directories
        for directory_path in directories:
            try:
                os.removedirs(directory_path)
            except OSError as exp:
                if exp.errno != 2:
                    LOG.error(str(exp))
                pass
71604
def recursively_get_files_from_directory(directory):
    
    return [
        os.path.join(root, filename)
        for root, directories, filenames in os.walk(directory)
        for filename in filenames
    ]
833266
def cd(path_to):  # pylint: disable=invalid-name
    
    if path_to == '-':
        if not cd.previous:
            raise PathError('No previous directory to return to')
        return cd(cd.previous)
    if not hasattr(path_to, 'cd'):
        path_to = makepath(path_to)
    try:
        previous = os.getcwd()
    except OSError as e:
        if 'No such file or directory' in str(e):
            return False
        raise
    if path_to.isdir():
        os.chdir(path_to)
    elif path_to.isfile():
        os.chdir(path_to.parent)
    elif not os.path.exists(path_to):
        return False
    else:
        raise PathError('Cannot cd to %s' % path_to)
    cd.previous = previous
    return True
1178037
def make_dirs_for_file_path(file_path, mode=0o775):
    
    dirname = os.path.dirname(file_path)
    if not os.path.exists(dirname):
        os.makedirs(dirname, mode=mode)
29583
def mkdir(cls, directory):
        
        directory = path_expand(directory)
        try:
            os.makedirs(directory)
        except OSError as e:

            # EEXIST (errno 17) occurs under two conditions when the path exists:
            # - it is a file
            # - it is a directory
            #
            # if it is a file, this is a valid error, otherwise, all
            # is fine.
            if e.errno == errno.EEXIST and os.path.isdir(directory):
                pass
            else:
                raise
326441
def all_files_in_directory(path):
    
    file_list = []
    for dirname, dirnames, filenames in os.walk(path):
        for filename in filenames:
            file_list.append(os.path.join(dirname, filename))
    return file_list
726206
def make_directory(self, directory_name, *args, **kwargs):
		
		previous_path = self.session_path()
		try:
			self.session_path(directory_name)
			os.mkdir(self.full_path())
		finally:
			self.session_path(previous_path)
410399
def list_path(root_dir):
    
    res = []
    if os.path.isdir(root_dir):
        for name in os.listdir(root_dir):
            res.append(name)
    return res
22439
def mkdir(path):
    
    try:
        os.makedirs(path)
        # sanity check
        if not os.path.isdir(path):  # pragma: no cover
            raise IOError('path is not a directory')
    except OSError as e:
        # EEXIST
        if e.errno == 17 and os.path.isdir(path):
            return
        raise