Skip to content

Instantly share code, notes, and snippets.

@helloqiu
Created January 19, 2018 04:36
Show Gist options
  • Save helloqiu/059c8efb550d1a55479919d663d05946 to your computer and use it in GitHub Desktop.
Save helloqiu/059c8efb550d1a55479919d663d05946 to your computer and use it in GitHub Desktop.
Move all files in sub dir out and delete dir.
# -*- 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