Finds content of folder recursively

    :param path: directory to get list of files and folders
    :param include_hidden: True iff include hidden files in list
    :return: List of paths in given directory recursively
190095
def ls_recurse(path, include_hidden=False):
    
    lst = []
    for file in os.listdir(path):
        hidden_file = FileSystem(file).is_hidden()
        if (hidden_file and include_hidden) or (not hidden_file):
            lst.append(os.path.join(path, file))
            if is_folder(os.path.join(path, file)):
                lst += ls_recurse(
                    os.path.join(path, file),
                    include_hidden=include_hidden
                )  # get list of files in directory
    return list(set(lst))
547598
def listdir_stat(dirname, show_hidden=True):
    
    import os
    try:
        files = os.listdir(dirname)
    except OSError:
        return None
    if dirname == '/':
        return list((file, stat('/' + file)) for file in files if is_visible(file) or show_hidden)
    return list((file, stat(dirname + '/' + file)) for file in files if is_visible(file) or show_hidden)
324010
def list(path, ext=None, start=None, stop=None, recursive=False):
        
        files = listflat(path, ext) if not recursive else listrecursive(path, ext)
        if len(files) < 1:
            raise FileNotFoundError('Cannot find files of type "%s" in %s'
                                    % (ext if ext else '*', path))
        files = select(files, start, stop)

        return files
1047156
def getchildren(self):
        '''
        
        '''
        try:
            if self.hidden:
                return [os.path.join(self.name, child)
                        for child in sorted(self.listdir(self.name))]
            else:
                return [os.path.join(self.name, child)
                        for child in sorted(os.listdir(self.name))]
        except OSError:
            return None
331075
def listdir(self, path):
        '''
        
        '''
        for f in os.listdir(path):
            if not f.startswith('.'):
                yield f
963342
def load_include_path(paths):
    
    for path in paths:
        # Verify the path is valid
        if not os.path.isdir(path):
            continue
        # Add path to the system path, to avoid name clashes
        # with mysql-connector for example ...
        if path not in sys.path:
            sys.path.insert(1, path)
        # Load all the files in path
        for f in os.listdir(path):
            # Are we a directory? If so process down the tree
            fpath = os.path.join(path, f)
            if os.path.isdir(fpath):
                load_include_path([fpath])
353906
def get_files(path, ext=[], include=True):
    
    has_ext = len(ext)>0
    for p, d, fs in os.walk(path):
        for f in fs:
            if has_ext:
                in_ext = False
                for name in ext:
                    if f.endswith(name):
                        in_ext = True
                        break
                if (include and in_ext) or \
                (not include and not in_ext):
                    yield os.path.join(p,f)
            else:
                yield os.path.join(p, f)
441065
def read_dir(path, folder):
    
    full_path = os.path.join(path, folder)
    fnames = glob(f"{full_path}/*.*")
    directories = glob(f"{full_path}/*/")
    if any(fnames):
        return [os.path.relpath(f,path) for f in fnames]
    elif any(directories):
        raise FileNotFoundError("{} has subdirectories but contains no files. Is your directory structure is correct?".format(full_path))
    else:
        raise FileNotFoundError("{} folder doesn't exist or is empty".format(full_path))
734206
def get_files(path:PathOrStr, extensions:Collection[str]=None, recurse:bool=False,
              include:Optional[Collection[str]]=None)->FilePathList:
    ""
    if recurse:
        res = []
        for i,(p,d,f) in enumerate(os.walk(path)):
            # skip hidden dirs
            if include is not None and i==0:  d[:] = [o for o in d if o in include]
            else:                             d[:] = [o for o in d if not o.startswith('.')]
            res += _get_files(path, p, f, extensions)
        return res
    else:
        f = [o.name for o in os.scandir(path) if o.is_file()]
        return _get_files(path, path, f, extensions)
411084
def _inclusion_check(self, path):
        # type: (_BaseSourcePaths, pathlib.Path) -> bool
        
        _spath = str(path)
        inc = True
        if self._include is not None:
            inc = any([fnmatch.fnmatch(_spath, x) for x in self._include])
        if inc and self._exclude is not None:
            inc = not any([fnmatch.fnmatch(_spath, x) for x in self._exclude])
        return inc
996310
def get_file_list(path):
    
    f_list = []
    def recur_dir(path, newpath = os.path.sep):
        files = os.listdir(path)
        for fle in files:
            f_path = cpjoin(path, fle)
            if os.path.isdir(f_path): recur_dir(f_path, cpjoin(newpath, fle))
            elif os.path.isfile(f_path): f_list.append(get_single_file_info(f_path, cpjoin(newpath, fle)))

    recur_dir(path)
    return f_list
31787
def find(self, path, all=False):
        '''
        
        '''
        found = os.path.join(settings.STATIC_ROOT, path)
        if all:
            return [found]
        else:
            return found
1320613
def recurse_tree(path, excludes, opts):
    
    # use absolute path for root, as relative paths like '../../foo' cause
    # 'if "/." in root ...' to filter out *all* modules otherwise
    path = os.path.abspath(path)
    # check if the base directory is a package and get is name
    if INIT in os.listdir(path):
        package_name = path.split(os.path.sep)[-1]
    else:
        package_name = None

    toc = []
    tree = os.walk(path, False)
    for root, subs, files in tree:
        # keep only the Python script files
        py_files =  sorted([f for f in files if os.path.splitext(f)[1] == '.py'])
        if INIT in py_files:
            py_files.remove(INIT)
            py_files.insert(0, INIT)
        # remove hidden ('.') and private ('_') directories
        subs = sorted([sub for sub in subs if sub[0] not in ['.', '_']])
        # check if there are valid files to process
        # TODO: could add check for windows hidden files
        if "/." in root or "/_" in root \
        or not py_files \
        or is_excluded(root, excludes):
            continue
        if INIT in py_files:
            # we are in package ...
            if (# ... with subpackage(s)
                subs
                or
                # ... with some module(s)
                len(py_files) > 1
                or
                # ... with a not-to-be-skipped INIT file
                not shall_skip(os.path.join(root, INIT))
               ):
                subroot = root[len(path):].lstrip(os.path.sep).replace(os.path.sep, '.')
                create_package_file(root, package_name, subroot, py_files, opts, subs)
                toc.append(makename(package_name, subroot))
        elif root == path:
            # if we are at the root level, we don't require it to be a package
            for py_file in py_files:
                if not shall_skip(os.path.join(path, py_file)):
                    module = os.path.splitext(py_file)[0]
                    create_module_file(package_name, module, opts)
                    toc.append(makename(package_name, module))

    # create the module's index
    if not opts.notoc:
        create_modules_toc_file(package_name, toc, opts)
137070
def glob_all(path=nil)
        Dir.chdir path || '.' do
          Pathname.glob("**/*", context.include_hidden_files? ? File::FNM_DOTMATCH : 0).sort.reject do |p|
            %w(. ..).include?(p.basename.to_s)
          end
        end
      end
86264
def list_files(scan_path, contains=None):
    
    file_list = []
    path = os.path.abspath(scan_path)
    for f in sorted(os.listdir(path)):
        if contains and f.find(contains) < 0:
            continue
        filepath = os.path.join(path, f)
        if os.path.isfile(filepath):
            file_list.append(filepath)
    return file_list
695293
def _get_modules(path):
    
    lst = []
    folder_contents = os.listdir(path)
    is_python_module = "__init__.py" in folder_contents

    if is_python_module:
        for file in folder_contents:
            full_path = os.path.join(path, file)

            if is_file(full_path):
                lst.append(full_path)

            if is_folder(full_path):
                lst += _get_modules(full_path)  # recurse in folder

    return list(set(lst))
224093
def get_subdirs(parent_path):
  
  entries = os.listdir(parent_path)
  subdirs = [(entry, os.path.join(parent_path, entry))
             for entry in entries
             if os.path.isdir(entry)]
  return subdirs