• <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 閱讀(1178) 評論(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无码久久综合影院| 国产精品久久久久久福利69堂| 91精品国产综合久久香蕉| 狠狠色丁香久久综合五月| 久久久久亚洲AV无码去区首| 国产免费久久精品99re丫y| 精品久久人妻av中文字幕| 狠狠色综合网站久久久久久久| 国内精品久久久久久久久电影网 | 东京热TOKYO综合久久精品| 成人a毛片久久免费播放| 久久久久精品国产亚洲AV无码| 久久99国产精品尤物| 亚洲精品成人网久久久久久| 久久精品人人做人人爽97| 色青青草原桃花久久综合| 久久国产精品77777| 亚洲国产成人精品女人久久久 | 久久人人爽人人澡人人高潮AV | 内射无码专区久久亚洲| 蜜臀av性久久久久蜜臀aⅴ麻豆| 久久精品无码一区二区三区免费| 久久精品国产亚洲精品2020 | 久久九九久精品国产| 97精品伊人久久大香线蕉app| 精品久久久无码人妻中文字幕| 国产高清国内精品福利99久久| 国内精品久久久久伊人av| 伊人久久大香线蕉综合5g| 久久国产精品免费一区| 四虎国产永久免费久久| 国产91久久精品一区二区| www.久久热.com| 久久精品天天中文字幕人妻| 亚洲精品乱码久久久久久中文字幕 | 人妻精品久久久久中文字幕69| 亚洲va中文字幕无码久久| 久久99热这里只频精品6| 久久久久久国产a免费观看黄色大片| 狠狠精品干练久久久无码中文字幕 | 久久久久久综合网天天|