|
@@ -0,0 +1,84 @@
|
|
1
|
+import os
|
|
2
|
+import tkinter as tk
|
|
3
|
+import numpy as np
|
|
4
|
+from tkinter import filedialog as tkFileDialog
|
|
5
|
+from tkinter import messagebox
|
|
6
|
+import shutil
|
|
7
|
+
|
|
8
|
+def start():
|
|
9
|
+ window = tk.Tk() # 创建窗口对象的背景色
|
|
10
|
+ window.title('复制文件程序') # 设置窗口的标题
|
|
11
|
+ window.geometry('400x250') # 设置窗口的大小
|
|
12
|
+ title = tk.Label(window, text='复制文件程序',
|
|
13
|
+ font=('微软雅黑', 12), width=40, height=3)
|
|
14
|
+ title.place(x=0, y=0, anchor='nw')
|
|
15
|
+ choosepath = tk.Label(window, text='选择源文件夹:',
|
|
16
|
+ font=('微软雅黑', 12), width=20, height=2)
|
|
17
|
+ choosepath.place(x=0, y=50, anchor='nw')
|
|
18
|
+ path_var1 = tk.StringVar() # 输入路径
|
|
19
|
+ entry1 = tk.Entry(window, textvariable=path_var1)
|
|
20
|
+ entry1.place(x=170, y=65, anchor='nw')
|
|
21
|
+
|
|
22
|
+ txtpath = tk.Label(window, text='选择txt:',
|
|
23
|
+ font=('微软雅黑', 12), width=20, height=2)
|
|
24
|
+ txtpath.place(x=0, y=100, anchor='nw')
|
|
25
|
+ path_var2 = tk.StringVar() # 输入路径
|
|
26
|
+ entry2 = tk.Entry(window, textvariable=path_var2)
|
|
27
|
+ entry2.place(x=170, y=115, anchor='nw')
|
|
28
|
+
|
|
29
|
+ resultpath = tk.Label(window, text='输出文件夹:',
|
|
30
|
+ font=('微软雅黑', 12), width=20, height=2)
|
|
31
|
+ resultpath.place(x=0, y=150, anchor='nw')
|
|
32
|
+ path_var6 = tk.StringVar() # 输出路径
|
|
33
|
+ entry6 = tk.Entry(window, textvariable=path_var6)
|
|
34
|
+ entry6.place(x=170, y=165, anchor='nw')
|
|
35
|
+
|
|
36
|
+ def choose2():
|
|
37
|
+ file_dir2 = tkFileDialog.askopenfilename(filetypes=[('TEXT', '*.txt'),('All Files', '*')])
|
|
38
|
+ path_var2.set(file_dir2)
|
|
39
|
+
|
|
40
|
+ def choose1():
|
|
41
|
+ file_dir1 = tkFileDialog.askdirectory()
|
|
42
|
+ path_var1.set(file_dir1)
|
|
43
|
+
|
|
44
|
+ def choose3():
|
|
45
|
+ file_dir6 = tkFileDialog.askdirectory()
|
|
46
|
+ path_var6.set(file_dir6)
|
|
47
|
+
|
|
48
|
+ def tuichu():
|
|
49
|
+ window.destroy()
|
|
50
|
+
|
|
51
|
+ def main():
|
|
52
|
+ inpath = entry1.get()
|
|
53
|
+ txtpath = entry2.get()
|
|
54
|
+ outpath = entry6.get()
|
|
55
|
+ #读取txt
|
|
56
|
+ with open(txtpath,'r') as filer:
|
|
57
|
+ for ln in filer:
|
|
58
|
+ str1 = ln.replace('\n','')
|
|
59
|
+ #完整路径
|
|
60
|
+ apath = inpath + '/' + str1
|
|
61
|
+ #验证下路径是否存在
|
|
62
|
+ if (os.path.exists(apath) == False):
|
|
63
|
+ print(apath + ' not exist!')
|
|
64
|
+ else:
|
|
65
|
+ opath = outpath + '/' + str1
|
|
66
|
+ #验证
|
|
67
|
+ if (os.path.exists(opath) == True):
|
|
68
|
+ print(opath + ' exist!')
|
|
69
|
+ opath = outpath + '/' + str1 + '_CT'
|
|
70
|
+ #复制
|
|
71
|
+ shutil.copytree(apath,opath)
|
|
72
|
+ messagebox.showinfo("消息","运行成功")
|
|
73
|
+ window.destroy()
|
|
74
|
+
|
|
75
|
+ tk.Button(window, text='选择', command=choose1).place(x=320, y=60, anchor='nw')
|
|
76
|
+ tk.Button(window, text='选择', command=choose2).place(x=320, y=110, anchor='nw')
|
|
77
|
+ tk.Button(window, text='选择', command=choose3).place(x=320, y=160, anchor='nw')
|
|
78
|
+ tk.Button(window,text='确认',command=main).place(x=120,y=210,anchor='nw')
|
|
79
|
+ tk.Button(window,text='取消',command=tuichu).place(x=220,y=210,anchor='nw')
|
|
80
|
+ window.mainloop()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+if __name__ == '__main__':
|
|
84
|
+ start()
|