Copying a file to an existing directory results in an IOError [Error 21] - This is a directory
You have already answered the question in the question.
dst
must be the path to the copied file. So if you want to copy a file to /var/lib/my/
, and your file is named f1
then there dst
should be/var/lib/my/f1.txt
Try to use shutil.copy
as proposed here , john-estess
shutil.copy(src, dst)
or try to fix it using the following snippet
shutil.copyfile(src, '%s/%s' % (dst, src.split('/')[-1]))
Assuming src is the path to the file you want to copy, for example /var/log/apache/access.log
and dst
is the path to the directory where you want to copy the file to, for example /var/lib/my
, and then the new destination /var/lib/my/access.log
.
source to share