os.walk exclude .svn folders

前端 未结 2 1172
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-13 11:16

I got a script that I want to use to change a repeated string throughout a project folder structure. Once changed then I can check this into SVN. However when I run my script it

2条回答
  •  感动是毒
    2021-02-13 12:01

    Err... what?

    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.

    for root, subFolders, files in os.walk(rootdir):
      try:
        subFolders.remove('.svn')
      except ValueError:
        pass
      dosomestuff()
    

提交回复
热议问题