• <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))

             

            日韩美女18网站久久精品| 国产精品久久久久久久午夜片| 久久久久亚洲精品无码网址| 很黄很污的网站久久mimi色| 久久国产精品-久久精品| 99久久精品无码一区二区毛片 | 久久精品9988| 国内精品久久久久久久coent| 久久婷婷色综合一区二区| 精品国产青草久久久久福利| 久久99国产精品久久99| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 亚洲国产精品狼友中文久久久| 亚洲色大成网站WWW久久九九| 欧美久久精品一级c片片| 无夜精品久久久久久| 久久精品一本到99热免费| 久久精品国产清自在天天线| 国产精品久久久久a影院| 91久久婷婷国产综合精品青草| 久久中文字幕视频、最近更新 | 日本精品久久久中文字幕| 久久精品国产99国产精品亚洲 | 99久久免费国产精品特黄| 久久久久国产精品| 色婷婷综合久久久久中文| 欧洲性大片xxxxx久久久| 国产成人香蕉久久久久| 久久99国产精品一区二区| 青草国产精品久久久久久| 国内精品伊人久久久久777| 亚洲欧美成人久久综合中文网| 精品久久久久久国产牛牛app| 久久精品九九亚洲精品天堂 | 午夜不卡久久精品无码免费| 亚洲国产成人久久综合碰| 久久久久亚洲AV无码去区首| 国产ww久久久久久久久久| 91久久九九无码成人网站| 99久久伊人精品综合观看| 久久亚洲精品中文字幕三区|