How to copy a file to a specific folder in a Python script?

Viewed 43307

I have the path of a file stored in a variable (say) filePath. I would like to copy that particular file to another specific folder within a Python script.

I tried

folderPath = (os.getcwd() + "/folder_name/") #to get the path of the folder
shutil.copyfile(filePath, folderPath)

But I got an error IOError: [Errno 21] Is a directory.

How can I solve this ?

My question might seem to be a duplicate of How do I copy a file in python? . But actually, I want to copy a file to a folder/directory whereas most answers to that question mention copying one file to another file.

3 Answers
Related