我正在編寫一個程序,將文件從一個文件夾移動到另一個文件夾。有時候我會在這個過程中覆蓋文件。但是,每當我運行該文件時,都會詢問「覆蓋C:...(是/否/全部)」。我希望我的程序自動選擇「全部」。預先感謝您用os模塊覆蓋python文件
import os
from tkinter import *
screen = Tk()
sourceplayers = 'C:\\Program Files (x86)\...\players'
destinationplayers = 'C:\\memory\Will\players'
sourceuserdata = ('C:\\\\Program Files (x86)\...\remote'
destinationuserdata = 'C:\\\\memory\\Will\\remote'
def copyout():
os.system ("""xcopy "%s" "%s" """ % (sourceplayers, destinationplayers))
os.system ("""xcopy "%s" "%s" """ % (sourceuserdata, destinationuserdata)) #save
def movein():
os.system ("""xcopy "%s" "%s" """ % (destinationplayers, sourceplayers))
os.system ("""xcopy "%s" "%s" """ % (destinationuserdata, sourceuserdata))
button = Button(screen, text="save", command=copyout)
button1 = Button(screen, text="overwrite", command=movein)
button.pack()
button1.pack()
screen.mainloop()
感謝您的回覆。我簡單地添加了/ y,它完美運行! –