forked from KraJacob/python_cours
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrie_fichier.py
44 lines (44 loc) · 1.86 KB
/
trie_fichier.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
34
35
36
37
38
39
40
41
42
43
44
import os
from glob import glob
import shutil
folders = ["Musique","Images","Video","Document"]
folder_source =r"D:\PERSO\python\cours_tp\tri_fichiers_sources"
source =r"D:\PERSO\python\cours_tp\tri_fichiers_sources\**"
files = glob(source,recursive=True)
for file in files:
if file.endswith(".jpg") or file.endswith(".jpeg") or file.endswith(".png"):
images = os.path.join(folder_source,"Images")
if os.path.exists(images):
file_source = os.path.join(folder_source,file)
shutil.move(file_source,images)
else:
os.makedirs(images,exist_ok=True)
file_source = os.path.join(folder_source, file)
shutil.move(file_source, images)
elif file.endswith(".pdf"):
docs = os.path.join(folder_source, "Documents")
if os.path.exists(docs):
file_source = os.path.join(folder_source, file)
shutil.move(file_source, docs)
else:
os.makedirs(docs, exist_ok=True)
file_source = os.path.join(folder_source, file)
shutil.move(file_source, docs)
elif file.endswith('.mp3') or file.endswith(".wav"):
musique = os.path.join(folder_source, "Musiques")
if os.path.exists(musique):
file_source = os.path.join(folder_source, file)
shutil.move(file_source, musique)
else:
os.makedirs(musique, exist_ok=True)
file_source = os.path.join(folder_source, file)
shutil.move(file_source, musique)
elif file.endswith(".mp4"):
video = os.path.join(folder_source, "Videos")
if os.path.exists(video):
file_source = os.path.join(folder_source, file)
shutil.move(file_source, video)
else:
os.makedirs(video, exist_ok=True)
file_source = os.path.join(folder_source, file)
shutil.move(file_source, video)