title: How do I create a specific number of subfolders, that depends on the number of objects in an image file, using Python?
body: <p>I am creating a script that crops individual objects within an image file, and I want to create a subfolder for each individual cropped image.</p>
  <p>This program was originally created in Matlab. This is the code:</p>
  <pre><code>tmgrph_cropDir = [writeParent_datDir '\Tomography Crops\ '  ];   %- Set path to new folder
  mkdir(tmgrph_cropDir);      % - Create new folder (write directory)
  
  %- Create subfolders for each object
  
   for k = 1 : length(measurements):                  
       obj_num = [&quot;\ &quot; sprintf(&quot;obj%03d&quot;,k)];      %- Set object folder
       tmgrphObj_cropDir = [tmgrph_cropDir obj_num];      % - Set object full path
       mkdir(tmgrphObj_cropDir);      %- Create object write directories
  
   end
  </code></pre>
  <p>I am trying to convert this to Python. Here is what I have so far:</p>
  <pre><code> dir_name = '\Tomography Crop\ '
   tmgrph_cropDir = os.path.join(writeParent_datDir, dir_name)
   os.mkdir(tmgrph_cropDir)
  
   #ROI_number - This is the number of cropped objects in the image 
  
   k=0
   for k in ROI_number:
        obj_num = '/ Obj 1/ '
        tmgrphObj_cropDir = os.path.append(tmgrph_datDir, obj_num)
        os.mkdir(tmgrphObj_cropDir)
   end
  </code></pre>
  <p>I get an error on the Python code.</p>
  <p>AttributeError: module 'ntpath' has no attribute 'append'</p>
  <p>Also, how would I get it to name each file according to the object. So 'obj 1', 'obj 2', 'obj 3' etc. Instead of just creating ROI_number number of subfolders all named the same thing.</p>
  <p>Thanks in advance!</p>