当前位置: 首页>>代码示例>>Python>>正文


Python scandir.scandir方法代码示例

本文整理汇总了Python中scandir.scandir方法的典型用法代码示例。如果您正苦于以下问题:Python scandir.scandir方法的具体用法?Python scandir.scandir怎么用?Python scandir.scandir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scandir的用法示例。


在下文中一共展示了scandir.scandir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: data_reader

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def data_reader(input_dir, shuffle=True):
  """Read images from input_dir then shuffle them
  Args:
    input_dir: string, path of input dir, e.g., /path/to/dir
  Returns:
    file_paths: list of strings
  """
  file_paths = []

  for img_file in scandir(input_dir):
    if img_file.name.endswith('.jpg') and img_file.is_file():
      file_paths.append(img_file.path)

  if shuffle:
    # Shuffle the ordering of all image files in order to guarantee
    # random ordering of the images with respect to label in the
    # saved TFRecord files. Make the randomization repeatable.
    shuffled_index = list(range(len(file_paths)))
    random.seed(12345)
    random.shuffle(shuffled_index)

    file_paths = [file_paths[i] for i in shuffled_index]

  return file_paths 
开发者ID:vanhuyz,项目名称:CycleGAN-TensorFlow,代码行数:26,代码来源:build_data.py

示例2: _iterdir

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def _iterdir(dirname, dironly):
    if not dirname:
        if isinstance(dirname, bytes):
            dirname = bytes(os.curdir, 'ASCII')
        else:
            dirname = os.curdir
    try:
        it = scandir(dirname)
        for entry in it:
            try:
                if not dironly or entry.is_dir():
                    yield entry.name
            except OSError:
                pass
    except OSError:
        return

# Recursively yields relative pathnames inside a literal directory. 
开发者ID:danhper,项目名称:bigcode-tools,代码行数:20,代码来源:glob.py

示例3: check_django

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def check_django():
    print("Checking for django app in site's content folder:")

    try:
        siteRoot = scandir.scandir(HOME_SITE)
        for entry in siteRoot:
            if not entry.name.startswith(APPSVC_VIRTUAL_ENV) and entry.is_dir():
                print("Detected directory: '" + entry.name + "'")
                subFolder = scandir.scandir(HOME_SITE + '/'+ entry.name)
                for subEntry in subFolder:
                    if subEntry.name == 'wsgi.py' and subEntry.is_file():
                        print("Found wsgi.py in directory '" + entry.name +  "', django app detection success")
                        return entry.name + '.wsgi'
    finally:
        print("django test returned ")

## Flask check: If 'application.py' is provided or a .py module is present, identify as Flask. 
开发者ID:Azure-App-Service,项目名称:python,代码行数:19,代码来源:entrypoint.py

示例4: data_reader

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def data_reader(input_dir, shuffle=True):
  """Read images from input_dir then shuffle them
  Args:
    input_dir: string, path of input dir, e.g., /path/to/dir
  Returns:
    file_paths: list of strings
  """
  file_paths = []


  for img_file in scandir(input_dir):
    if img_file.name.endswith('.jpg') and img_file.is_file():
      file_paths.append(img_file.path)

  if shuffle:
    # Shuffle the ordering of all image files in order to guarantee
    # random ordering of the images with respect to label in the
    # saved TFRecord files. Make the randomization repeatable.
    shuffled_index = list(range(len(file_paths)))
    random.seed(12345)
    random.shuffle(shuffled_index)

    file_paths = [file_paths[i] for i in shuffled_index]

  return file_paths 
开发者ID:engindeniz,项目名称:Cycle-Dehaze,代码行数:27,代码来源:build_data.py

示例5: _scandir

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def _scandir(path, onerror, followlinks):
    dirs = []
    files = []
    links = []

    try:
        scandir_it = scandir(path)

    except (IOError, OSError) as exc:
        if onerror is not None:
            onerror(exc)
        return

    try:
        for entry in _scaniter(scandir_it, onerror):

            if entry.is_file(follow_symlinks=False):
                files.append(entry)

            elif entry.is_dir(followlinks):
                dirs.append(entry)

            elif entry.is_file():
                links.append(entry)

        return dirs, files, links

    finally:
        try:
            scandir_it.close()
        except AttributeError:
            pass 
开发者ID:deplicate,项目名称:deplicate,代码行数:34,代码来源:common.py

示例6: scantree

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def scantree(path):
    # type: (str) -> os.DirEntry
    """Recursively scan a directory tree
    :param str path: path to scan
    :rtype: DirEntry
    :return: DirEntry via generator
    """
    for entry in scandir(path):
        if entry.is_dir(follow_symlinks=True):
            # due to python2 compat, cannot use yield from here
            for t in scantree(entry.path):
                yield t
        else:
            yield entry 
开发者ID:Azure,项目名称:batch-shipyard,代码行数:16,代码来源:util.py

示例7: __init__

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def __init__(self, path):
        self.iterator = scandir(path) 
开发者ID:pypa,项目名称:pipenv,代码行数:4,代码来源:setup_info.py

示例8: scan_presets

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def scan_presets():
    """Iterate over presets.

    Every time this function is called a search in `PRESETS_DIR` is performed.
    """
    for entry in scandir(PRESETS_DIR):
        if entry.is_file():
            yield entry.name 
开发者ID:FrancescoCeruti,项目名称:linux-show-player,代码行数:10,代码来源:lib.py

示例9: scan_styles

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def scan_styles():
    """Scan for "installed" styles."""
    LiSPStyles.clear()

    for entry in scandir(StylesPath):
        if entry.is_dir():
            has_qss = os.path.exists(os.path.join(entry.path, 'style.qss'))
            has_py = os.path.exists(os.path.join(entry.path, 'style.py'))

            if has_qss or has_py:
                LiSPStyles[entry.name.title()] = Style(
                    path=entry.path,
                    has_qss=has_qss,
                    has_py=has_py
                ) 
开发者ID:FrancescoCeruti,项目名称:linux-show-player,代码行数:17,代码来源:styles.py

示例10: load

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def load(self):
        """Generate lists of tuples (class-name, class-object)."""
        for entry in scandir(self.pkg_path):

            # Exclude __init__, __pycache__ and likely
            if re.match('^__.*', entry.name):
                continue

            mod_name = entry.name
            if entry.is_file():
                # Split filename and extension
                mod_name, ext = os.path.splitext(entry.name)

                # Exclude all non-python files
                if not re.match('.py[cod]?', ext):
                    continue

            # Exclude excluded ¯\_(ツ)_/¯
            if mod_name in self.excluded:
                continue

            mod_path = self.pkg + '.' + mod_name

            try:
                # Import module
                module = import_module(mod_path)

                # Load class from imported module
                for prefix, suffix in zip(self.prefixes, self.suffixes):
                    name = self._class_name(mod_name, prefix, suffix)
                    if hasattr(module, name):
                        cls = getattr(module, name)
                        yield (name, cls)

            except ImportError:
                logging.warning('Cannot load module: {0}'.format(mod_name))
                logging.debug(traceback.format_exc()) 
开发者ID:FrancescoCeruti,项目名称:linux-show-player,代码行数:39,代码来源:loading.py

示例11: existing_locales

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def existing_locales():
    for entry in scandir('lisp/i18n'):
        if entry.name.startswith('lisp_') and entry.name.endswith('.ts'):
            yield entry.name[5:-3]

# Locales of which generate translations files 
开发者ID:FrancescoCeruti,项目名称:linux-show-player,代码行数:8,代码来源:i18n_update.py

示例12: generate_for_submodules

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def generate_for_submodules(path, qm=False):
    # Here "modules" is used generically
    modules = [entry.path for entry in scandir(path) if entry.is_dir()]
    for module in modules:
        if os.path.exists(os.path.join(module, 'i18n')):
            create_pro_file(module)
            p_file = os.path.join(module, os.path.basename(module) + '.pro')
            if qm:
                subprocess.run(['lrelease', p_file],
                               stdout=sys.stdout,
                               stderr=sys.stderr)
            else:
                subprocess.run(PYLUPDATE_CMD + [p_file],
                               stdout=sys.stdout,
                               stderr=sys.stderr) 
开发者ID:FrancescoCeruti,项目名称:linux-show-player,代码行数:17,代码来源:i18n_update.py

示例13: check_flask

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def check_flask():
    print("Checking for flask app in site's content folder:")

    try:
        siteRoot = scandir.scandir(HOME_SITE)
        for entry in siteRoot:
            if entry.is_file() and (entry.name == "application.py" or entry.name == "app.py"):
                print("found app '" + entry.name + "' in root folder, flask app detection success")
                return entry.name[:-3] + ":app"

        return None
    finally:
        print("flask test returned") 
开发者ID:Azure-App-Service,项目名称:python,代码行数:15,代码来源:entrypoint.py

示例14: paths

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def paths(self, root=None):
        root = root or self.root_directory
        for entry in scandir.scandir(root):
            if entry.is_dir():
                for filename in self.paths(entry.path):
                    yield filename
            elif self.regexp.match(os.path.join(root, entry.name)):
                self.count += 1
                yield os.path.join(root, entry.name) 
开发者ID:criteo,项目名称:biggraphite,代码行数:11,代码来源:import_whisper.py

示例15: scandir

# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def scandir(path):
    try:
        return _scandir(path)

    # fallback for systems where sys.getfilesystemencoding() returns the "wrong" value
    except UnicodeDecodeError:
        return scandir_listdir_fallback(path) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:9,代码来源:io.py


注:本文中的scandir.scandir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。