import os n = 1 while True: dirname = 'usbdisk%d' % n if not os.path.exists(dirname): os.mkdir(dirname) break n += 1 print 'done'