Move child folder contents to parent folder in python

后端 未结 4 861
走了就别回头了
走了就别回头了 2021-01-05 06:27

I have a specific problem in python. Below is my folder structure.

dstfolder/slave1/slave

I want the contents of \'slave\' folder to

4条回答
  •  清酒与你
    2021-01-05 06:46

    Example using the os and shutil modules:

    from os.path import join
    from os import listdir, rmdir
    from shutil import move
    
    root = 'dstfolder/slave1'
    for filename in listdir(join(root, 'slave')):
        move(join(root, 'slave', filename), join(root, filename))
    rmdir(root)
    

提交回复
热议问题