Copying a file to an existing directory results in IOError [Error 21] is a directory
You're using the wrong function. You might want "copy":
https://docs.python.org/2/library/shutil.html
You have already answered yourself in the question.
dst
should be the path to the copied file. So if you want to copy the file to /var/lib/my/
and your file is called f1
then dst
should be /var/lib/my/f1.txt
Try to use shutil.copy
as suggested here by john-estess
shutil.copy(src, dst)
or try to fix this using the following snippet
shutil.copyfile(src, '%s/%s' % (dst, src.split('/')[-1]))
Assuming src is the path of the file you want to copy, such as /var/log/apache/access.log
, and dst
is the path to the directory, where you want to copy the file, for example, /var/lib/my
then the new destination is /var/lib/my/access.log
.