

Target = os.path.join(target, os.path.dirname(source)) Also, this method will sync the permissions of the target file with the source after copying its content. It too throws the SameFileError if you are copying the same file. It means if the target is a folder, then it’ll create a new file inside it with the same name ( basename) as the source file. The copy() method functions like the “cp” command in Unix. shutil copy() method # SyntaxĬopyfile(source_file, )

Print("\nHere follows the file content:\n")Ĭontinue 2. Print("Do you like to print the file ? (y/n): ") Print("Unexpected error:", sys.exc_info()) With open("hello.txt", mode="w") as file: # Copy a File using Shutil copyfile() method

