How to get all of the immediate subdirectories in Python

前端 未结 15 1656
旧时难觅i
旧时难觅i 2020-11-29 17:09

I\'m trying to write a simple Python script that will copy a index.tpl to index.html in all of the subdirectories (with a few exceptions).

I\'m getting bogged down

15条回答
  •  情歌与酒
    2020-11-29 17:33

    os.walk is your friend in this situation.

    Straight from the documentation:

    walk() generates 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).

提交回复
热议问题