-
Notifications
You must be signed in to change notification settings - Fork 0
/
os modul.py
89 lines (87 loc) · 3.35 KB
/
os modul.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
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
83
84
85
86
87
88
89
import os
from datetime import datetime
"""print(os.getcwd())
os.chdir("C:/Users/User-HP/PycharmProjects/pythonProject")
os.mkdir("C:/Users/User-HP/PycharmProjects/pythonProject/book")
for file in os.listdir():
print(file)
os.makedirs("Python1/Python2/Python3")
for i,j,k in os.walk("C:/Users/User-HP/PycharmProjects/pythonProject/Python1"):
print(f"Path: {i}")
print(f"Folder: {j}")
print(f"File: {k}")
print("---------------------------------------------------------------------------------------------------------------")
print(os.path.isfile("Euler.py"))
print(os.path.isdir("Python3"))
print(os.path.splitext("sade_murekkeb_reqem.py"))
os.rename("book","kitab")
os.rmdir("kitab")
os.removedirs("Python1/Python2/Text3.txt")
for i,j,k in os.walk("C:/Users/User-HP/PycharmProjects/pythonProject/Python1/Python2"):
print(i)
print(j)
print(k)
print("****************************************************************************************************************")
os.remove("Text3.txt")"""
# file-lari uzantilarina gore folder-lere ayirmaq
"""def sirala():
folder=input("Siralanacaq folder: ")
files=[] #file-lar yigilacaq
uzantilar=[] # uzantilar yigilacaq
def list_dir():
for file in os.listdir(folder):
if os.path.isdir(os.path.join(folder,file)): # file folder-dir mi?
continue
if file.startswith("."): # file hide-dirmi?
continue
else:
files.append(file)
list_dir()
# Uzantilari almaq
for file in files:
uzanti=file.split(".")[-1]
if uzanti in uzantilar: # Uzanti daha evvel elave olundu?
continue
else:
uzantilar.append(uzanti)
for uzanti in uzantilar: # folder yaradilir
if os.path.isdir(os.path.join(folder,uzanti)):
continue
else:
os.mkdir(os.path.join(folder,uzanti))
for file in files:
uzanti=file.split(".")[-1]
os.rename(os.path.join(folder,file),os.path.join(folder,uzanti,file))
sirala()"""
# file-lari tarixlerine gore folder-lere ayirmaq
def tarixle():
folder = input("Ayrilacaq folder: ")
files = [] # file-lari yigacaq
tarixler = [] # tarix-leri yigacaq
def tarix_dir():
for file in os.listdir(folder):
if os.path.isdir(os.path.join(folder, file)): # file folder-dir mi?
continue
if file.startswith("."): # file hide-dir mi?
continue
else:
files.append(file)
tarix_dir()
# Tarixleri almaq
for file in files:
tarix_damgasi = os.stat(os.path.join(folder, file)).st_birthtime
tarix = datetime.fromtimestamp(tarix_damgasi).strftime("%d-%m-%Y")
if tarix in tarixler: # tarix daha evvel elave olunub?
continue
else:
tarixler.append(tarix)
for tarix in tarixler:
if os.path.isdir(os.path.join(folder, tarix)):
continue
else:
os.mkdir(os.path.join(folder, tarix))
for file in files:
tarix_damgasi = os.stat(os.path.join(folder, file)).st_birthtime
tarix = datetime.fromtimestamp(tarix_damgasi).strftime("%d-%m-%Y")
os.rename(os.path.join(folder, file), os.path.join(folder, tarix, file))
tarixle()