title: Data of 1 folder gets added to another
body: <p>I have a small script which checks if my object is present in image or not. If present then it writes the image to a folder.There are multiple sub-folders inside.On writing, the data for 1st folder works fine but when data is written to the 2nd sub-folder then the data of 1st folder is also appended along-with the data of 2nd folder</p>
  
  <p>The code works perfectly fine except the problem that while writing the data to disk the data of 1st sub-folder is also appended to the data of 2nd sub-folder. Below is my code</p>
  
  <pre><code>def target_non_target(input_frames_folder,model_file,output):
  
      if not os.path.exists(output):
          os.makedirs(output,exist_ok=True)
  
      count=0
      folders = glob(input_frames_folder)
  
      img_list = []
  
  
      for folder in folders:
          folder_name=os.path.basename(folder)
          #print(folder_name)
          out_path = output +"\\" + folder_name
          print(out_path)
          os.makedirs(out_path,exist_ok=True)
  
  
  
          for f in glob(folder+"/*.jpg"):
              img_list.append(f)
  
          for i in range(len(img_list)):
              v1=os.path.basename(img_list[i])
              img_name = os.path.splitext(v1)[0]
              image = cv2.imread(img_list[i])
              orig = image.copy()
  
              image = cv2.resize(image, (28, 28))
              image = image.astype("float") / 255.0
              image = img_to_array(image)
              image = np.expand_dims(image, axis=0)
  
  
              print("[INFO] loading network...")
              model = load_model(model_file)
  
  
              (non_target, target) = model.predict(image)[0]
  
              if target &gt; non_target:
                  label = "Target"
  
              else:
                  label = "Non Target"
  
              probab = target if target &gt; non_target else non_target
              label = "{}: {:.2f}%".format(label, probab * 100)
  
  
              op = imutils.resize(orig, width=400)
              cv2.putText(op, label, (10, 25),  cv2.FONT_HERSHEY_SIMPLEX,0.7, (0, 255, 0), 2)
  
              if target &gt; non_target:
                  cv2.imwrite(out_path+"/"+"\\{}.jpg".format(img_name),orig)
              cv2.waitKey(0)
  
      #return target_op
  
  
  frames_folder = ("C:\\Python36\\videos\\videos_new\\*")
  
  model = ("C:\\Python35\\target_non_target\\target_non_target.model")
  
  output_folder = ("C:\\Python35\\target_non_target\\Target_images_new\\")
  
  target_check = target_non_target(frames_folder,model,output_folder)
  </code></pre>
  
  <p>Suppose there are 2 sub-folders A and B inside a main folder X.There will be many more sub-folders.While writing output to disk the data of A is written perfectly but while writing data for B the data of folder A and folder B both are getting appended into B folder. I want the data to be in their respective folders. Any idea what changes could be made in my script for getting the desired output</p>