I'm just doing an exercise where I have a list of files (given as absolute paths), which should be copied to a given directory if some sort of flag is set. This is my function to copy the files:
def copy_to(paths, dst):
if not os.path.exists(dst):
os.makedirs(dst)
for path in paths:
shutil.copy(path, dst)
However, the given solution looks different:
def copy_to(paths, dst):
if not os.path.exists(dst):
os.makedirs(dst)
for path in paths:
basename = os.path.basename(path)
shutil.copy(path, os.path.join(dst, basename))
Is getting the basename of the path and joining it with the path where to copy to really needed here?