當前位置: 首頁>>代碼示例>>Python>>正文


Python os.Walk方法代碼示例

本文整理匯總了Python中os.Walk方法的典型用法代碼示例。如果您正苦於以下問題:Python os.Walk方法的具體用法?Python os.Walk怎麽用?Python os.Walk使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在os的用法示例。


在下文中一共展示了os.Walk方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ListRecursively

# 需要導入模塊: import os [as 別名]
# 或者: from os import Walk [as 別名]
def ListRecursively(top):
  """Walks a directory tree, yielding (dir_path, file_paths) tuples.

  For each of `top` and its subdirectories, yields a tuple containing the path
  to the directory and the path to each of the contained files.  Note that
  unlike os.Walk()/gfile.Walk(), this does not list subdirectories and the file
  paths are all absolute.

  If the directory does not exist, this yields nothing.

  Args:
    top: A path to a directory..
  Yields:
    A list of (dir_path, file_paths) tuples.
  """
  for dir_path, _, filenames in gfile.Walk(top):
    yield (dir_path, (os.path.join(dir_path, filename)
                      for filename in filenames)) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:20,代碼來源:io_wrapper.py

示例2: ListRecursivelyViaWalking

# 需要導入模塊: import os [as 別名]
# 或者: from os import Walk [as 別名]
def ListRecursivelyViaWalking(top):
    """Walks a directory tree, yielding (dir_path, file_paths) tuples.

    For each of `top` and its subdirectories, yields a tuple containing the path
    to the directory and the path to each of the contained files.  Note that
    unlike os.Walk()/tf.io.gfile.walk()/ListRecursivelyViaGlobbing, this does not
    list subdirectories. The file paths are all absolute. If the directory does
    not exist, this yields nothing.

    Walking may be incredibly slow on certain file systems.

    Args:
      top: A path to a directory.

    Yields:
      A (dir_path, file_paths) tuple for each directory/subdirectory.
    """
    for dir_path, _, filenames in tf.io.gfile.walk(top, topdown=True):
        yield (
            dir_path,
            (os.path.join(dir_path, filename) for filename in filenames),
        ) 
開發者ID:tensorflow,項目名稱:tensorboard,代碼行數:24,代碼來源:io_wrapper.py

示例3: ListRecursively

# 需要導入模塊: import os [as 別名]
# 或者: from os import Walk [as 別名]
def ListRecursively(top):
  """Walks a directory tree, yielding (dir_path, file_paths) tuples.

  For each of `top` and its subdirectories, yields a tuple containing the path
  to the directory and the path to each of the contained files.  Note that
  unlike os.Walk()/tf.gfile.Walk(), this does not list subdirectories and the
  file paths are all absolute.

  If the directory does not exist, this yields nothing.

  Args:
    top: A path to a directory..
  Yields:
    A list of (dir_path, file_paths) tuples.
  """
  for dir_path, _, filenames in tf.gfile.Walk(top):
    yield (dir_path, (os.path.join(dir_path, filename)
                      for filename in filenames)) 
開發者ID:PacktPublishing,項目名稱:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代碼行數:20,代碼來源:io_wrapper.py


注:本文中的os.Walk方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。