-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWIN.DIR.SORTING.py
33 lines (33 loc) · 2.27 KB
/
WIN.DIR.SORTING.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
27
28
29
30
31
32
33
#--
#-- ************************************************************************************************************:
#-- ********************************************* SORT DIRECTORY ***********************************************:
#-- ************************************************************************************************************:
#-- Author: JBALLARD (JEB) :
#-- Date: 2023.3.07 :
#-- Script: WIN.DIR.SORTING.py :
#-- Purpose: A python script that sorts files in a directory. :
#-- Class: python -m pip install os :
#-- Class: python3 -m pip install os :
#-- Version: 1.0 :
#-- ************************************************************************************************************:
#-- ************************************************************************************************************:
#--
#-- ********************************************************:
#-- DEFINE PARAMS, CONSTANTS, CONFIG PATHS, IMPORT CLASSES :
#-- ********************************************************:
import os
from shutil import move
#--
#-- SORT FILES:
def sort_files(directory_path):
for filename in os.listdir(directory_path):
if os.path.isfile(os.path.join(directory_path, filename)):
file_extension = filename.split('.')[-1]
destination_directory = os.path.join(directory_path, file_extension)
if not os.path.exists(destination_directory):
os.makedirs(destination_directory)
move(os.path.join(directory_path, filename), os.path.join(destination_directory, filename))
#--
#-- ********************************************************:
#-- END OF PYTHON SCRIPT :
#-- ********************************************************: