python - Creating 100+ folders and naming them sequentially -


i'm trying create 143 folders using os.makedirs() tool, i'm having trouble. can generate 1 folder @ time, , i'd make of them @ once. folders named img_0016 through img_00160.

i thought of trying loop counter, each loop add new number end of folder title, can't work.

import os  folders in range(0, 143):     count = 0016      os.makedirs("c:\\users\joshuarb\desktop\organized_images\img"+count)      count = count+1 

it easier , more readable use direct numbers (note want use 161 in range() call, since last number not included):

import os  count in range (16, 161):     os.makedirs("c:\\users\joshuarb\desktop\organized_images\img_{:04d}".format(count)) 

also notice used zero-padding width 4, since naming convention differs img_0016 , img_00160 chose limit dos' usual 8-character. adjust according needs.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -