| import os |
| import shutil |
| from os.path import join, getsize |
| |
| |
| shutil.move(src_file, dst_dir) |
| |
| shutil.copyfile(src_file, dst_file) |
| |
| os.remove(target_file) |
| |
| os.mkdir(target_dir) |
| |
| for filename in os.listdir(target_dir): |
| pass |
| |
| shutil.rmtree(target_dir) |
| |
| |
| |
| def get_dir_size(target_dir): |
| size = 0 |
| for root, dirs, files in os.walk(target_dir): |
| size += sum([getsize(join(root, name)) for name in files]) |
| return size |
| |
| |
| |
| def copy_dir(src_dir, dst_dir): |
| if os.path.isdir(src_dir) and os.path.isdir(dst_dir): |
| filelist_src = os.listdir(src_dir) |
| for file in filelist_src: |
| src_path = os.path.join(os.path.abspath(src_dir), file) |
| if os.path.isdir(src_path): |
| dst_path = os.path.join(os.path.abspath(dst_dir), file) |
| if not os.path.exists(dst_path): |
| os.mkdir(dst_path) |
| copy_dir(src_path, dst_path) |
| else: |
| with open(src_path, 'rb') as read_stream: |
| contents = read_stream.read() |
| dst_path = os.path.join(dst_dir, file) |
| with open(dst_path, 'wb') as write_stream: |
| write_stream.write(contents) |
| return True |
| |
| else: |
| return False |