


# https://www.globalsino.com/ICs/page4853.html
# Add a new line to the beginning of a text file

import shutil
from pathlib import Path

File_Merge_to_Top = open("C:\GlobalSino\images\Temp.txt", 'w')

# The new line to add
File_Merge_to_Top.write("This is my new line adding to the top of the new file\n")

File_Merge_to_Top = Path(r'C:\GlobalSino\images\Temp.txt')
File_Merge_to_Bottom = Path(r'C:\GlobalSino\images\MyFile.txt')
  
newfile = input("Enter the name of the new file: ")
print("The merged content of the 2 files will be in", newfile)
  
with open(newfile, "wb") as wfd:  
    for f in [File_Merge_to_Top, File_Merge_to_Bottom]:
        with open(f, "rb") as fd:
            shutil.copyfileobj(fd, wfd)
  
print("\nThe two files have been merged.")
print("Do you want to the content of the file? (y / n): ")
  
Answer = input().lower()
if Answer == 'y':
    print()
    c = open(newfile, "r")
    print(c.read())
    c.close()
else:
    exit()
