I am trying to make a simple tool which will copy/move files with certain extension from one place to another. Everything is working out pretty much fine, but I am trying to make it possible to type in the directory where you want to copy from, and choose the directory where you want to copy to.
myGUI=Tk()
myGUI.geometry("400x200+100+200")
myGUI.title('Copy dat')
Source=StringVar()
Destination=StringVar()
MySource=Entry(myGUI, textvariable=Source).grid(row=9, column=2)
MyDestination=Entry(myGUI, textvariable=Destination).grid(row=10, column=2)
def copyy():
source = os.listdir("Source")
destination = "Destination"
for files in source:
if files.endswith(".jpg"):
shutil.copy(files, destination)
button1=Button(myGUI, text=" Copy ", command=copyy).grid(row=3, column=0)
But if I click on my button, the error message says that windows can't find directory named /Source or something like that. So I understand source = os.listdir("Source")
is the problem. And I guess destination = "Destination"
is also incorect.
If I put the whole path in the code the copy button works well, but I want it to be possible to write the path in the window by the user of the tool. Please help.
edit: The whole code if needed:
import shutil
import os
from tkinter import *
myGUI=Tk()
myGUI.geometry("400x200+100+200")
myGUI.title('Copy dat')
Source=StringVar()
Destination=StringVar()
MySource=Entry(myGUI, textvariable=Source).grid(row=9, column=2)
MyDestination=Entry(myGUI, textvariable=Destination).grid(row=10, column=2)
def copyy():
source = os.listdir('Source')
destination = "Destination"
for files in source:
if files.endswith(".jpg"):
shutil.copy(files, destination)
def movee():
source = os.listdir("C:/Users/PC/Desktop/python testing/")
destination = "C:/Users/PC/Desktop/python testing/destination"
for files in source:
if files.endswith(".jpg"):
shutil.move(files, destination)
label1=Label(myGUI, text='Welcome to the copy utility', fg='Blue').grid(row=0,column=2)
label2=Label(myGUI, text='Ultimate JPG mover', fg='Black').grid(row=1,column=0)
label3=Label(myGUI, text='(Thing\'s actually pretty useless)', fg='Black').grid(row=2,column=0)
button1=Button(myGUI, text=" Copy ", command=copyy).grid(row=3, column=0)
button2=Button(myGUI, text=" Move ", command=movee).grid(row=5, column=0)
myGUI.mainloop()