本文整理汇总了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
示例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.
示例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.
示例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
示例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
示例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
示例7: __init__
# 需要导入模块: import scandir [as 别名]
# 或者: from scandir import scandir [as 别名]
def __init__(self, path):
self.iterator = scandir(path)
示例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
示例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
)
示例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())
示例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
示例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)
示例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")
示例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)
示例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)