import os maxindex = 2 for i in range(maxindex): dirname = "usbdisk" + str(i) try: os.stat(dirname) except: os.mkdir(dirname) print 'done'