forked from DhanushNehru/Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileOrganizer.py
26 lines (21 loc) · 933 Bytes
/
FileOrganizer.py
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
import os
import shutil
# Prompt the user for the directory path to organize files
path = input("Enter path: ")
# List all files in the specified directory
files = os.listdir(path)
# Iterate through each file in the directory
for file in files:
# Split the filename and extension
filename, extension = os.path.splitext(file)
# Remove the leading dot from the extension for folder naming
extension = extension[1:]
# Check if a directory for the file extension already exists
if os.path.exists(path + '/' + extension):
# Move the file to the corresponding extension folder
shutil.move(path + '/' + file, path + '/' + extension + '/' + file)
else:
# If the directory does not exist, create it
os.makedirs(path + '/' + extension)
# Move the file to the newly created extension folder
shutil.move(path + '/' + file, path + '/' + extension + '/' + file)