error copying folder with python
<p>i made a program that copy automatically a usb device.
when it copy the usb it create one folder in correct destination, and one folder in the same path of python program. i want that itcreate only one folder in correct destination! thanks</p>

<p>this is the code:</p>

<pre><code>import shutil
from array import *
import math
import time
import os
import sys
import random
import datetime


def data():
     now = datetime.datetime.now()
     format = "%d %b %H.%M"
     global now_date
     now_date = now.strftime(format)
     format = "%M"
     global minuti
     minuti = now.strftime(format)

data()
old_date = now_date

alfabeto = ['A:','B:','F:','G:','H:','I:','L:','M:','N:','O:',] #mancano e,c,d

a = (r'')
b=random.choice('abcdefghilmnopqrstuvz1234567890Ã¨Ã²Ã Ã¹')
new_dir = '{}'.format(now_date) 
inc = (r'C:\documenti\program\file\collegamenti\'') 
incollaa = "".join([inc, new_dir,' ',b])
i=0

while True:
     try:
          if i==10:  i=0
          time.sleep(1)          
          copiaa = "".join([a, alfabeto[i]])
          i=i+1
          shutil.copytree(copiaa,incollaa)
          if not os.path.exists(new_dir):  
                 os.makedirs(new_dir)


          break
     except FileNotFoundError:
          pass
</code></pre>

<p>Your problem is the following lines:</p>

<pre><code>if not os.path.exists(new_dir):  
    os.makedirs(new_dir)
</code></pre>

<p>Since <code>new_dir</code> is a relative path (a date string), it will be created in the working folder of your script.</p>

python python-3.x subprocess folder copy-paste