-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove_jpg_files.py
More file actions
82 lines (62 loc) · 2.5 KB
/
move_jpg_files.py
File metadata and controls
82 lines (62 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import shutil
import tkinter as tk
from tkinter import filedialog, messagebox, ttk
def move_jpg_files(files, destination_folder):
"""Move selected JPG files to destination folder."""
if not files:
messagebox.showwarning("No Files", "Please select JPG files first.")
return
if not destination_folder:
messagebox.showwarning("No Destination", "Please select a destination folder.")
return
os.makedirs(destination_folder, exist_ok=True)
moved = 0
for file_path in files:
if file_path.lower().endswith(('.jpg', '.jpeg')):
file_name = os.path.basename(file_path)
dest_path = os.path.join(destination_folder, file_name)
shutil.copy2(file_path, dest_path)
moved += 1
messagebox.showinfo("Success", f"✅ {moved} JPG files have been copied successfully!")
def select_files():
"""Select multiple JPG files (default to Downloads folder)."""
downloads_path = os.path.join(os.path.expanduser("~"), "Downloads")
file_paths = filedialog.askopenfilenames(
title="Select JPG Files",
initialdir=downloads_path,
filetypes=[("JPG files", "*.jpg;*.jpeg")]
)
if file_paths:
selected_files.clear()
selected_files.extend(file_paths)
file_list.delete(0, tk.END)
for file in selected_files:
file_list.insert(tk.END, os.path.basename(file))
def select_destination():
"""Choose destination folder."""
folder = filedialog.askdirectory(title="Select Destination Folder")
if folder:
destination_path.set(folder)
def start_move():
"""Move selected JPG files."""
move_jpg_files(selected_files, destination_path.get())
# --- UI Setup ---
root = tk.Tk()
root.title("JPG File Mover")
root.geometry("500x400")
root.resizable(False, False)
selected_files = []
destination_path = tk.StringVar()
# --- UI Layout ---
ttk.Label(root, text="📁 Select JPG Files", font=("Segoe UI", 12, "bold")).pack(pady=10)
ttk.Button(root, text="Browse Files", command=select_files).pack()
file_list = tk.Listbox(root, width=60, height=8)
file_list.pack(pady=10)
ttk.Label(root, text="Destination Folder:", font=("Segoe UI", 10)).pack()
dest_frame = ttk.Frame(root)
dest_frame.pack(pady=5)
ttk.Entry(dest_frame, textvariable=destination_path, width=40).pack(side=tk.LEFT, padx=5)
ttk.Button(dest_frame, text="Browse", command=select_destination).pack(side=tk.LEFT)
ttk.Button(root, text="Move JPG Files", command=start_move).pack(pady=20)
root.mainloop()