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


Python genericpath.isdir方法代碼示例

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


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

示例1: walk

# 需要導入模塊: import genericpath [as 別名]
# 或者: from genericpath import isdir [as 別名]
def walk(top, func, arg):
    """Directory tree walk with callback function.

    For each directory in the directory tree rooted at top (including top
    itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
    dirname is the name of the directory, and fnames a list of the names of
    the files and subdirectories in dirname (excluding '.' and '..').  func
    may modify the fnames list in-place (e.g. via del or slice assignment),
    and walk will only recurse into the subdirectories whose names remain in
    fnames; this can be used to implement a filter, or to impose a specific
    order of visiting.  No semantics are defined for, or required of, arg,
    beyond that arg is always passed to func.  It can be used, e.g., to pass
    a filename pattern, or a mutable object designed to accumulate
    statistics.  Passing None for arg is common."""
    warnings.warnpy3k("In 3.x, os.path.walk is removed in favor of os.walk.",
                      stacklevel=2)
    try:
        names = os.listdir(top)
    except os.error:
        return
    func(arg, top, names)
    for name in names:
        name = join(top, name)
        if isdir(name):
            walk(name, func, arg)


# Expand paths beginning with '~' or '~user'.
# '~' means $HOME; '~user' means that user's home directory.
# If the path doesn't begin with '~', or if the user or $HOME is unknown,
# the path is returned unchanged (leaving error reporting to whatever
# function is called with the expanded path as argument).
# See also module 'glob' for expansion of *, ? and [...] in pathnames.
# (A function should also be defined to do full *sh-style environment
# variable expansion.) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:37,代碼來源:ntpath.py

示例2: add_directory_csv_files

# 需要導入模塊: import genericpath [as 別名]
# 或者: from genericpath import isdir [as 別名]
def add_directory_csv_files(dir_path, paths=None):
    if not paths:
        paths = []

    for p in listdir(dir_path):
        path = join(dir_path, p)
        if isdir(path):
            # call recursively for each dir
            paths = add_directory_csv_files(path, paths)
        elif isfile(path) and path.endswith('.csv'):
            # add every file to the list
            paths.append(path)

    return paths 
開發者ID:NervanaSystems,項目名稱:coach,代碼行數:16,代碼來源:globals.py


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