-2

I have this directory structure...

└── 01048
    └── 2014
        └── IN

I want to merge this directory structure...

└── 01048
    └── 2014
        └── AR
        └── AB

To make this directory structure...

└── 01048
    └── 2014
        └── IN
        └── AR
        └── AB

I've tried shutil.move("../scr_path/01048", "../destination_path/01048") but that results in...

└── 01048
    └── 01048
        └── 2014
            └── AR
            └── AB
    └── 2014
        └── IN
Sam Luther
  • 1,170
  • 3
  • 18
  • 38

2 Answers2

0

You used the wrong destination path:

shutil.move("../scr_path/01048", "../destination_path")

If the destination directory already exists, you will have an error. In order to merge two directory trees you can check the answer here.

Community
  • 1
  • 1
enrico.bacis
  • 30,497
  • 10
  • 86
  • 115
0

You should try-out shutil.move , along with os.listdir() to move your directories.

Example -

import os, os.path
import shutil
for src in os.listdir('../scr_path/01048'):
    s = os.path.join('../scr_path/01048',src)
    d = os.path.join('../destination_path/01048',src)
    for src1 in os.listdir(s):
        shutil.move(os.path.join(s,src1),d)
Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176