Retrieves directory entries.

    Since a directory can contain a vast number of entries using
    a generator is more memory efficient.

    Yields:
      ZipPathSpec: a path specification.
199888
def _EntriesGenerator(self):
    
    location = getattr(self.path_spec, 'location', None)

    if location and location.startswith(self._file_system.PATH_SEPARATOR):
      # The zip_info filename does not have the leading path separator
      # as the location string does.
      zip_path = location[1:]

      # Set of top level sub directories that have been yielded.
      processed_directories = set()

      zip_file = self._file_system.GetZipFile()
      for zip_info in zip_file.infolist():
        path = getattr(zip_info, 'filename', None)
        if path is not None and not isinstance(path, py2to3.UNICODE_TYPE):
          try:
            path = path.decode(self._file_system.encoding)
          except UnicodeDecodeError:
            path = None

        if not path or not path.startswith(zip_path):
          continue

        # Ignore the directory itself.
        if path == zip_path:
          continue

        path_segment, suffix = self._file_system.GetPathSegmentAndSuffix(
            zip_path, path)
        if not path_segment:
          continue

        # Some times the ZIP file lacks directories, therefore we will
        # provide virtual ones.
        if suffix:
          path_spec_location = self._file_system.JoinPath([
              location, path_segment])
          is_directory = True
        else:
          path_spec_location = self._file_system.JoinPath([path])
          is_directory = path.endswith('/')

        if is_directory:
          if path_spec_location in processed_directories:
            continue
          processed_directories.add(path_spec_location)
          # Restore / at end path to indicate a directory.
          path_spec_location += self._file_system.PATH_SEPARATOR

        yield zip_path_spec.ZipPathSpec(
            location=path_spec_location, parent=self.path_spec.parent)
749302
def iter_directory(directory):
    """"""
    for path, dir, files in os.walk(directory):
        for f in files:
            filepath = os.path.join(path, f)
            key = os.path.relpath(filepath, directory)
            yield (filepath, key)
404652
def _get_files(self) -> Iterator[str]:
        
        path = os.path.abspath(self.path)
        if os.path.isfile(path):
            path = os.path.dirname(path)

        for path in self._get_parents(path):
            for file_path in self._get_files_from_dir(path):
                yield file_path
429775
def find_files(self):
        ''''''
        for path in self.paths:
            for subpath, dirs, files in os.walk(path):
                for filename in files:
                    (name, ext) = os.path.splitext(filename)
                    if ext in self.extensions:
                        yield os.path.join(subpath, filename)
1151202
static FileEntry obtainDirectoryFileEntry(String path) {
    try {
      FileEntry lastEntry = null;
      Constructor<FileEntry> c =
          FileEntry.class.getDeclaredConstructor(FileEntry.class, String.class, int.class,
              boolean.class);
      c.setAccessible(true);
      for (String part : path.split("/")) {
        lastEntry = c.newInstance(lastEntry, part, TYPE_DIRECTORY, lastEntry == null);
      }
      return lastEntry;
    } catch (NoSuchMethodException ignored) {
    } catch (InvocationTargetException ignored) {
    } catch (InstantiationException ignored) {
    } catch (IllegalAccessException ignored) {
    }
    return null;
  }
817998
def get_directories_re(
            self,
            directory_re,
            full_path=False,
            ignorecase=False):
        """"""
        if ignorecase:
            compiled_re = re.compile(directory_re, re.I)
        else:
            compiled_re = re.compile(directory_re)

        found = set()

        if self.handle:
            for member in self.handle.getmembers():
                # zipfiles only list directories => have to work around that
                if isinstance(member, ZipInfo):
                    to_match = os.path.dirname(member.name)
                # tarfiles => only match directories
                elif isinstance(member, TarInfo) and member.isdir():
                    to_match = member.name
                else:
                    to_match = None
                if to_match:
                    if ((full_path and compiled_re.search(to_match)) or (
                            not full_path and compiled_re.search(
                                os.path.basename(to_match)))):
                        found.add(to_match)

        return list(found)
1021322
def filepaths(self):
        
        if self.path is not None:
            yield from utils.filepaths(self.path, exclude=self.exclude,
                                       hidden=False, empty=False)
439615
def get_dirs_for_path(*paths):
    
    for path in paths:
        head = path
        while head:
            head, tail = os.path.split(head)
            if head:
                yield head
            else:
                # We don't need to yield empty path
                break
470343
def _GetSubFileEntries(self):
    
    tar_file = self._file_system.GetTARFile()

    if self._directory is None:
      self._directory = self._GetDirectory()

    if self._directory and tar_file:
      for path_spec in self._directory.entries:
        location = getattr(path_spec, 'location', None)
        if location is None:
          continue

        kwargs = {}
        try:
          kwargs['tar_info'] = tar_file.getmember(location[1:])
        except KeyError:
          kwargs['is_virtual'] = True

        yield TARFileEntry(
            self._resolver_context, self._file_system, path_spec, **kwargs)
784727
def _GetDirectory(self):
    
    if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
      return None
    return VShadowDirectory(self._file_system, self.path_spec)
823089
def get_paths(directory):
    '''
    '''
    fnames = [os.path.join(directory, f)
              for f in os.listdir(directory)
              if os.path.isfile(os.path.join(directory, f))
              and not f.startswith('.')]
    return fnames
173055
def directory_files(path):
    """"""

    for entry in os.scandir(path):
        if not entry.name.startswith('.') and entry.is_file():
            yield entry.name
1133798
def dirs(self):
        """"""
        contents = self.paths
        contents = (VenvDir(path.path) for path in contents if path.is_dir)
        return contents
1164834
def _get_memory_banks_listed_in_dir(path):
    """"""
    # Such directories contain entries named "node<id>" for each memory bank
    return [int(entry[4:]) for entry in os.listdir(path) if entry.startswith('node')]
1254923
def entries_in_tree(self, prefix, tree):
        
        for entry in tree.items():
            if prefix:
                new_prefix = prefix + (entry.path.decode(), )
            else:
                new_prefix = (entry.path.decode(), )

            yield (new_prefix, stat.S_ISDIR(entry.mode), entry.sha)
948723
public String []list(String path) throws IOException
  {
    if (path.startsWith("/")) {
      path = path.substring(1);
    }
    
    if (! path.endsWith("/")) {
      path = path + "/";
    }

    ArrayList<String> names = new ArrayList<>();
    
    ZipFile zipFile = getZipFile();
    
    try {
      Enumeration<? extends ZipEntry> e = zipFile.entries();
      
      while (e.hasMoreElements()) {
        ZipEntry entry = e.nextElement();
        
        String name = entry.getName();

        if (name.startsWith(path)) {
          String tail = name.substring(path.length());
          int p = tail.indexOf('/');
          
          if (p >= 0) {
            tail = tail.substring(0, p);
          }
          
          if (! tail.equals("") && ! names.contains(tail)) {
            names.add(tail);
          }
        }
      }
    } finally {
      closeZipFile(zipFile);
    }
    
    String []list = new String[names.size()];
    
    names.toArray(list);
    
    return list;
  }
619638
def _GetDirectory(self):
    
    if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
      return None

    return APFSContainerDirectory(self._file_system, self.path_spec)