Skip to content

Commit c7e0207

Browse files
committed
I removed empty new lines
1 parent 76a0fa3 commit c7e0207

File tree

1 file changed

+22
-50
lines changed

1 file changed

+22
-50
lines changed

File_Organizer/file-organizer.py

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,40 @@
22
from watchdog.observers import Observer
33
from watchdog.events import FileSystemEventHandler
44
import shutil
5-
65
class MyHandler(FileSystemEventHandler):
76
def on_created(self, event):
87
if not event.is_directory:
9-
file_path = event.src_path
10-
file_name = os.path.basename(file_path)
11-
file_extension = os.path.splitext(file_name)[1].lower()
12-
13-
14-
15-
# A dictionary takes file extensions & folder to move each formats to.
16-
destination_mapping = {
17-
#Key = Format/extension to handle : Value = Folder to move file format.
18-
19-
".zip": r"C:\Users\Precious pc\Documents\Zip files",
20-
".png": r"C:\Users\Precious pc\Documents\png_files",
21-
".psd": r"C:\Users\Precious pc\Documents\psd_destination",
22-
".pdf": r"C:\Users\Precious pc\Documents\pdf_files",
23-
}
24-
25-
26-
# Default destination for unknown extensions
27-
other_files = r"C:\Users\Precious pc\Documents\other_files"
28-
29-
# Get the destination directory for the file extension or use the default
30-
destination = destination_mapping.get(file_extension, other_files)
31-
32-
# Move the file to the determined destination
33-
34-
# Check if file already exists in destination & delete it.
35-
if os.path.exists(os.path.join(destination, file_name)):
36-
print(f"File {file_name} already exists in the destination. Deleting it.")
37-
os.remove(os.path.join(destination, file_name))
38-
39-
# Move the file to the determined destination
40-
shutil.move(file_path, destination)
41-
8+
file_path = event.src_path
9+
file_name = os.path.basename(file_path)
10+
file_extension = os.path.splitext(file_name)[1].lower()
11+
# A dictionary takes file extensions & folder to move each formats to.
12+
destination_mapping = {
13+
# Key = Format/extension to handle : Value = Folder to move file format.
14+
".zip": r"C:\Users\Precious pc\Documents\Zip files",
15+
".png": r"C:\Users\Precious pc\Documents\png_files",
16+
".psd": r"C:\Users\Precious pc\Documents\psd_destination",
17+
".pdf": r"C:\Users\Precious pc\Documents\pdf_files",
18+
}
19+
# Default destination for unknown extensions
20+
other_files = r"C:\Users\Precious pc\Documents\other_files"
21+
# Get the destination directory for the file extension or use the default
22+
destination = destination_mapping.get(file_extension, other_files)
23+
# Move the file to the determined destination
24+
# Check if file already exists in destination & delete it.
25+
if os.path.exists(os.path.join(destination, file_name)):
26+
print(f"File {file_name} already exists in the destination. Deleting it.")
27+
os.remove(os.path.join(destination, file_name))
28+
# Move the file to the determined destination
29+
shutil.move(file_path, destination)
4230
if __name__ == "__main__":
4331
folder_to_watch = r"C:\Users\Precious pc\Documents\monitor" # Replace with the directory you want to monitor
4432
event_handler = MyHandler()
4533
observer = Observer()
4634
observer.schedule(event_handler, path=folder_to_watch, recursive=False) # Set recursive to True if you want to monitor subdirectories
4735
observer.start()
48-
4936
try:
5037
while True:
5138
pass
5239
except KeyboardInterrupt:
5340
observer.stop()
5441
observer.join()
55-
56-
57-
58-
59-
60-
61-
62-
63-
64-
65-
66-
67-
68-
69-

0 commit comments

Comments
 (0)