-
Notifications
You must be signed in to change notification settings - Fork 0
/
dosya.py
181 lines (173 loc) · 6.1 KB
/
dosya.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import glob
import os
import re
from pathlib import Path
import colorama
# from colorama import Fore, Back, Style
# colorama.init()
s="."
treeString=""
treeCounter=2
silmessage=False
silinenObje=Path()
yaratmessage=False
class Dosya:
def __init__(self,pathNFileName):
self.pathNFileName=Path(pathNFileName)
self.fileName=str(pathNFileName).split("/")[-1]
self.fileStrings=self.fileName.split(".")
self.SecondNameFlag=False
self.fileExtension=False
if len(self.fileStrings)==3:
self.SecondNameFlag=True
self.fileExtension=True
self.fileFirstName=self.fileStrings[0]
self.fileSecondName=self.fileStrings[1]
self.fileExtension=self.fileStrings[2]
if len(self.fileStrings)==2:
self.fileExtension=True
self.fileFirstName=self.fileStrings[0]
self.fileExtension=self.fileStrings[1]
if len(self.fileStrings)==1:
self.fileFirstName=self.fileStrings[0]
def isimDegistir(self,fileName):
s=str(self.pathNFileName.parent)+"/"+fileName
# self.pathNFileName.rename(s)
self.__init__(s)
print(self.fileName)
# self.fileName=fileName
# self.fileStrings=fileName.split(".")
# self.SecondNameFlag=False
# self.fileExtension=False
# if len(self.fileStrings)==3:
# self.SecondNameFlag=True
# self.fileExtension=True
# self.fileFirstName=self.fileStrings[0]
# self.fileSecondName=self.fileStrings[1]
# self.fileExtension=self.fileStrings[2]
# if len(self.fileStrings)==2:
# self.fileExtension=True
# self.fileFirstName=self.fileStrings[0]
# self.fileExtension=self.fileStrings[1]
# if len(self.fileStrings)==1:
# self.fileFirstName=self.fileStrings[0]
def sil(self):
global silmessage
global silinenObje
# silmessage=self.pathNFileName
silmessage=True
silinenObje=self.pathNFileName
self.pathNFileName.unlink()
returnString="silinen dosya: "+str(silinenObje)
return returnString
def yaz(self,String):
self.pathNFileName.write_text(String)
def oku(self):
return self.pathNFileName.read_text()
def __str__(self):
s=self.fileName
return s
def __repr__(self):
return "Dosya Nesnesi: {}".format(self.fileName)
class Klasor:
def __init__(self,path):
self.path=Path(path)
self.name=self.path.parts[-1]
self.__dosyaListesi=self.dosyalar(initial=True)
self.__klasorListesi=self.klasorler(initial=True)
def dosyalar(self,initial=None):
global silmessage
global silinenObje
global yaratmessage
dosyaListesi=[Dosya(dosya) for dosya in self.path.iterdir() if dosya.is_file()]
if initial or silmessage or yaratmessage :
self.__dosyaListesi=[Dosya(dosya) for dosya in self.path.iterdir() if dosya.is_file()]
silmessage=False
yaratmessage=False
return self.__dosyaListesi
def klasorler(self,initial=None):
global silmessage
global yaratmessage
if initial or silmessage or yaratmessage:
self.__klasorListesi=[Klasor(str(altKlasor)) for altKlasor in self.path.iterdir() if altKlasor.is_dir()]
silmessage=False
yaratmessage=False
return self.__klasorListesi
def dosyaSil(self,fileName):
path2File=Path()
path2File=self.path / fileName
p = [dosya for dosya in self.__dosyaListesi if path2File==dosya.pathNFileName][0]
p.sil()
def dosyaYarat(self,fileName):
global yaratmessage
path2File=Path()
path2File=self.path / fileName
path2File.touch()
yaratmessage=True
# print(path2File)
# print(path2File.exists())
def klasorYarat(self,klasorName):
global yaratmessage
path2File=Path()
path2File=self.path / klasorName
path2File.mkdir()
yaratmessage=True
def klasoruSil(self):
try:
self.path.rmdir()
except Exception as e:
print(e)
def altKlasorSil(self,klasorName):
path2Klasor=Path()
path2Klasor=self.path / klasorName
p=None
try:
p=[klasor for klasor in self.__klasorListesi if path2Klasor==klasor.path][0]
except Exception as e:
print("No such folder")
if p!=None:
p.klasoruSil()
else:
print("Nothing done!")
def __genTree(self):
global treeString
global treeCounter
if self.path.parent ==Path("."):
treeString=treeString+color.project+self.name+color.end
if self.__dosyaListesi !=[]:
treeCounter=treeCounter+2
for dosya in self.__dosyaListesi:
treeString=treeString+"\n"+treeCounter*" "+"|__"+color.dosya+dosya.fileName+color.end
treeCounter=treeCounter-2
for altKlasor in self.__klasorListesi:
treeCounter=treeCounter+2
treeString=treeString+"\n"+treeCounter*" "+"|__"+color.directory+altKlasor.name+color.end
altKlasor.__genTree()
treeCounter=treeCounter-2
def tree(self):
self.__genTree()
print(treeString)
treeCounter=0
def dosyaBul(self,fileName):
path2File=Path()
path2File=self.path / fileName
p = [dosya for dosya in self.__dosyaListesi if path2File==dosya.pathNFileName][0]
return p
def __str__(self):
global silmessage
if silmessage:
self.__init__()
silmessage=False
s="Klasor: {}\n dosyaListesi: {}\n klasorListesi: {}".format(self.path,self.__dosyaListesi,self.__klasorListesi)
return s
def __repr__(self):
global silmessage
if silmessage:
self.__init__()
silmessage=False
return "Klasor Nesnesi: {}".format(self.name)
class color:
project="\033[0;0;35m"
directory="\033[0;0;33m"
dosya="\033[0;0;34m"
end='\033[0m'