How to get all of the immediate subdirectories in Python

前端 未结 15 1686
旧时难觅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:31

    I just wrote some code to move vmware virtual machines around, and ended up using os.path and shutil to accomplish file copying between sub-directories.

    def copy_client_files (file_src, file_dst):
        for file in os.listdir(file_src):
                print "Copying file: %s" % file
                shutil.copy(os.path.join(file_src, file), os.path.join(file_dst, file))
    

    It's not terribly elegant, but it does work.

提交回复
热议问题