• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            我希望你是我獨家記憶

            一段永遠封存的記憶,隨風而去
            posts - 263, comments - 31, trackbacks - 0, articles - 3
               :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

            os.walk()

            Posted on 2009-07-29 10:59 Hero 閱讀(1171) 評論(0)  編輯 收藏 引用 所屬分類: python

             

            Generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames).

            dirpath 
            is a string, the path to the directory. dirnames is a list of the names of the subdirectories in dirpath (excluding '.' and '..'). filenames is a list of the names of the non-directory files in dirpath. Note that the names in the lists contain no path components. To get a full path (which begins with top) to a file or directory in dirpath, do os.path.join(dirpath, name).

            If optional argument topdown 
            is True or not specified, the triple for a directory is generated before the triples for any of its subdirectories (directories are generated top-down). If topdown is False, the triple for a directory is generated after the triples for all of its subdirectories (directories are generated bottom-up).

            When topdown 
            is True, the caller can modify the dirnames list in-place (perhaps using del or slice assignment), and walk() will only recurse into the subdirectories whose names remain in dirnames; this can be used to prune the search, impose a specific order of visiting, or even to inform walk() about directories the caller creates or renames before it resumes walk() again. Modifying dirnames when topdown is False is ineffective, because in bottom-up mode the directories in dirnames are generated before dirpath itself is generated.

            By default errors 
            from the listdir() call are ignored. If optional argument onerror is specified, it should be a function; it will be called with one argument, an OSError instance. It can report the error to continue with the walk, or raise the exception to abort the walk. Note that the filename is available as the filename attribute of the exception object.

            By default, walk() will 
            not walk down into symbolic links that resolve to directories. Set followlinks to True to visit directories pointed to by symlinks, on systems that support them.

            New 
            in version 2.6: The followlinks parameter.

            Note

            Be aware that setting followlinks to True can lead to infinite recursion 
            if a link points to a parent directory of itself. walk() does not keep track of the directories it visited already.

            Note

            If you 
            pass a relative pathname, don’t change the current working directory between resumptions of walk(). walk() never changes the current directory, and assumes that its caller doesn’t either.

            This example displays the number of bytes taken by non
            -directory files in each directory under the starting directory, except that it doesn’t look under any CVS subdirectory:

            import os
            from os.path import join, getsize
            for root, dirs, files in os.walk('python/Lib/email'):
                
            print root, "consumes",
                
            print sum(getsize(join(root, name)) for name in files),
                
            print "bytes in", len(files), "non-directory files"
                
            if 'CVS' in dirs:
                    dirs.remove(
            'CVS')  # don't visit CVS directories
            In the next example, walking the tree bottom-up is essential: rmdir() doesn’t allow deleting a directory before the directory is empty:

            # Delete everything reachable from the directory named in "top",
            #
             assuming there are no symbolic links.
            #
             CAUTION:  This is dangerous!  For example, if top == '/', it
            #
             could delete all your disk files.
            import os
            for root, dirs, files in os.walk(top, topdown=False):
                
            for name in files:
                    os.remove(os.path.join(root, name))
                
            for name in dirs:
                    os.rmdir(os.path.join(root, name))

             

            精品无码人妻久久久久久| 久久精品水蜜桃av综合天堂| 日本一区精品久久久久影院| 999久久久免费国产精品播放| 久久艹国产| 亚洲精品美女久久久久99| 88久久精品无码一区二区毛片| 亚洲国产天堂久久综合| 国产精品久久久久天天影视| 亚洲精品乱码久久久久久不卡| 漂亮人妻被黑人久久精品| 欧美午夜精品久久久久久浪潮| 欧美黑人又粗又大久久久| 欧美精品丝袜久久久中文字幕 | 久久久久国产成人精品亚洲午夜| 久久人人爽人人爽人人片AV不 | 亚洲女久久久噜噜噜熟女| 久久久久久a亚洲欧洲aⅴ| 99精品国产免费久久久久久下载| 久久中文字幕一区二区| 亚洲va久久久噜噜噜久久天堂 | 99久久久久| 99久久免费国产精精品| 日本强好片久久久久久AAA | 久久天堂电影网| 久久精品无码午夜福利理论片| 四虎国产精品成人免费久久| 精品无码久久久久久久动漫| 久久青青草原亚洲av无码app | 色8激情欧美成人久久综合电| 久久精品国产影库免费看| 久久精品国产亚洲av水果派| 少妇内射兰兰久久| 亚洲欧美日韩中文久久| 久久精品免费全国观看国产| 日韩欧美亚洲国产精品字幕久久久| 国产高清国内精品福利99久久| 国产精品成人精品久久久| 亚洲国产二区三区久久| 久久精品国产欧美日韩| 亚洲国产日韩综合久久精品|