I’m trying to implement this shell expression cp ~/.config/profiles/* $HOME
in python with shutil
But I can’t find optimal method that would check if file is a directory for me, instead I’m ending up with this code:
for file_path in Path().home().joinpath(".config/profiles").iterdir():
filename = str(file_path).split("/")[-1]
destination = Path.home().joinpath(filename)
if not destination.exists() and file_path.exists():
copytree(src=file_path, dst=destination) if file_path.is_dir() else copy(src=file_path, dst=destination)
print(destination, file_path)
I thought that maybe it’s the design of shutil, but then I found shutil.move
method that basically moves file or directory to the destination.
(https://docs.python.org/3/library/shutil.html#shutil.copy)
shutil.move(src, dst, copy_function=copy2)¶
Recursively move a file or directory (src) to another location and return the destination.
Can you tell how I can copy file or directory to the destination without any conditions, because I couldn’t find any related method in shutil