-3

I'm trying to create a program to spam new folders, but I cannot get it to work, I keep getting

TypeError: cannot concatenate 'str' and 'int' objects 

but I am converting the string amount into an integer already

import os
def folderSpam():
    amount = raw_input("Please insert how many folders you want to create: ")
    amount = int(amount)
    path = raw_input("Please insert the directory to create the folders in: ")
    msg = raw_input("Please insert the spam name of the folders")
    for i in range(0, amount):
        amount0 = 0
        if amount0 == amount:
            exit()
        else:
            amount0 = amount0 + 1
            os.chdir(path)
            os.mkdir(msg + amount0)
            print "All folders have been created"
McGrady
  • 10,869
  • 13
  • 47
  • 69
Logan
  • 9
  • 2
  • 1
    The error is pretty clear: `msg + amount0` doesn't work. Try this instead: `msg + str(amount0)` – Julien Apr 11 '17 at 04:17

1 Answers1

1

Use str(amount0) to do string and int concatenation.

Please check Python String and Integer concatenation for more details

import os
    def folderSpam():
        amount = raw_input("Please insert how many folders you want to create: ")
        amount = int(amount)
        path = raw_input("Please insert the directory to create the folders in: ")
        msg = raw_input("Please insert the spam name of the folders")
        for i in range(0, amount):
            amount0 = 0
            if amount0 == amount:
                exit()
            else:
                amount0 = amount0 + 1
                os.chdir(path)
                os.mkdir(msg + str(amount0))
                print "All folders have been created"
Community
  • 1
  • 1
prashant
  • 2,181
  • 2
  • 22
  • 37