Created
January 19, 2018 04:36
-
-
Save helloqiu/059c8efb550d1a55479919d663d05946 to your computer and use it in GitHub Desktop.
Move all files in sub dir out and delete dir.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import os | |
base_path = os.path.abspath("./") | |
def move_out(path, target_path): | |
dirs = os.listdir(path) | |
for file in dirs: | |
p = os.path.join(path, file) | |
if os.path.isdir(p): | |
move_out(p, target_path) | |
os.rmdir(p) | |
else: | |
os.rename(p, os.path.join(target_path, file)) | |
if __name__ == "__main__": | |
move_out('./', './') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment