-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFile Finder
318 lines (314 loc) · 9.33 KB
/
File Finder
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import json
import os.path
import shutil
import json
from web3 import Web3
import os
import time
import stat
import subprocess
def currPath():
return os.getcwd()
def home_it():
curr = currPath()
slash = '//'
if '//' not in str(curr):
slash = '/'
changeGlob('slash',slash)
changeGlob('home',curr)
return home
def changeGlob(x,v):
globals()[x] = v
#HomeFunctions---------------------------------------------------------------------------------------------------------------------------------------------------------------
def removeFromList(x,y):
i = findIt(x,y)
if i == len(y):
return y[:-1]
ls = []
for i in range(0,len(y)):
if y[i] != x:
ls.append(y[i])
return ls
def openFileExplorer(x):
x ='open '+x
subprocess.Popen(x, shell=True)
def allSizeDays(x,ls,i):
return timeSpacing(ls,i,str(calcTimeInDays(foldTime(x,ls,i))),str(calcKb(foldSize(x,ls,i))))
def getFolder(x):
exit = False
n = x
avoid = True
#avoid = boolAsk("avoid hidden?")
while exit != True:
foldList = os.listdir(x)
if avoid == True:
foldList = removeFromList(foldList,'.',0)
ask = create_ask(foldList,'which file would you like to use?')
if ask == "exit":
exit == True
elif ask == "back":
n = buildToSplitLast(n,slash)
elif ask == "open":
openFileExplorer(x)
elif str(ask) in foldList:
n = n+slash+ask
else:
n = n+slash+ask
if isFold(n) == True:
if boolAsk(fileInputString(splitTo(n,slash,-1))) == False:
n = buildToSplitLast(n,slash)
else:
return n
x = n+slash
#ASKfunctions-----------------------------------------------------------------------------
def create_ask(x,y):
alph = get_alph()
n = y + '\n0) to exit\n1) back\n2) openFileExplorer\n3) enter filePath\n\n'
alph = createAlph(len(x))
alphGood = ['0','1','2','3']
for i in range(0,len(x)):
alphGood.append(alph[i])
n = n + str(alph[i]) + ') '+str(x[i])+'\n'
while True:
ask = input(n)
if ask in alphGood:
if ask == str(0):
return True
if ask == str(1):
return "back"
if ask == str(2):
return "open"
if ask == str(3):
return "custom"
i = find_it_alph(alph,str(ask))
return x[i]
print('looks like you entered an input that was not selectable,please re-input your selection')
def boolAsk(x):
yes = ['y','yes','true','t','','0']
no = ['n','no','false','f',1]
ask = input(x+'\n0) yes\n1) no\n')
ask = str(ask).lower()
if ask.lower() in lowerList(yes):
return True
return False
def isFile(x):
return os.path.isfile(x)
def buildToSplitLast(x,y):
nSpl = splitIt(x,y)
n = ''
if nSpl != False:
for i in range(0,len(nSpl)-1):
n += nSpl[i] + y
return removeLast(n,y)
return x
def removeFromList(x,y,i):
newLs = []
if i == int(-1):
for l in range(0,len(x)):
if y not in x[l]:
newLs.append(x[l])
else:
for l in range(0,len(x)):
if y != x[l][i]:
newLs.append(x[l])
return newLs
def fileInputString(x):
return "is "+str(x)+" the file you would like to choose?"
def splitTo(x,spl,i):
tryIt = x
num = splitNum(x,spl)
keepUp = True
while keepUp == True:
if i == -1 and num == 1:
return x
tryIt = x.split(spl)[i]
if num > i:
if fileInputString(tryIt) != False:
return tryIt
i +=1
def isTypeFile(x,path,ls):
lsN,lsN2 = [],[]
for i in range(0,len(ls)):
if isFile(createPath(path,ls[i])):
if x in ls[i]:
lsN.append(ls[i])
if isFold(createPath(path,ls[i])):
lsN2.append(ls[i])
for i in range(0,len(lsN)):
lsN2.append(lsN[i])
return lsN2
def fileAsk():
while True:
file = str(AnyAsk(['please enter a file path','enter here: ']))
if file == 'exit':
return file
print(file,file.split(slash)[-1],isFile(file))
if isFile(file) == True:
if '.py' not in file.split(slash)[-1]:
if boolAsk('looks as if the file '+str(x.split(slash)[-1])+' is not a python file, did you want to continue anyway?'):
return file
else:
return file
else:
print('looks like that is not a recognized file')
def lowerList(x):
lsN = []
if isLs(x) == False:
x = [x]
for i in range(0,len(x)):
lsN.append(str(x[i]).lower())
return lsN
def AnyAsk(x):
if len(x) == 2:
inp = x[0]+'\n0) exit\n'+x[1]
else:
inp = x+'\n0) exit\n'
ask = input(inp)
if ask == '0':
return 'exit'
return ask
#CleanStrings--------------------------------------------------------------------------------------------------------------------------------------------
def find_it_alph(x,k):
i = 0
print(x)
while str(x[i]) != str(k):
i = i + 1
return i
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
def findIt(x,ls):
for i in range(0,len(ls)):
if x == ls[i]:
return i
return None
def findIt(x,y):
for i in range(0,len(y)):
if y[i] == x:
return i
return False
def calcTimeInDays(x):
return str(round((getTime()-x)/(60*24*60),2))+' days'
def calcKb(x):
return str(round(x/1000,2))+' kb'
def foldTime(x,ls,i):
return os.stat(x+'/'+ls[i])[9]
def foldSize(x,ls,i):
return os.stat(x+'/'+ls[i])[6]
def timeSpacing(x,i,time,size):
teb = ' \t'
h = x[i]
var = [time,size]
teb = ' '
exSpace = len(str()+teb)-len(str(x[i]))
for k in range(0,2):
te = ' \t'
if k ==0:
te = ' \t'
now = exSpace-(len(x)+len(te))
take = int(now)/len(' ')
for c in range(0,int(exSpace)):
h = h+' '
h = h+te+var[k]
return h
def createAlph(i):
k = int(i/int(26) + 1)
alph = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z'.split(',')
alphNew = []
alLen = i
for l in range(0,k):
lenNow = i
if i>int(26):
lenNow = int(26)
for c in range(0,lenNow):
n = alph[c]
for ck in range(0,l):
n = n + alph[c]
alphNew.append(n)
i -=1
return alphNew
def get_alph():
alph = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz,aaa,bbb,ccc,ddd,eee,fff,ggg,hhh,iii,jjj,kkk,lll,mmm,nnn,ooo,ppp,qqq,rrr,sss,ttt,uuu,vvv,www,xxx,yyy,zzz,aaaa,bbbb,cccc,dddd,eee,fff,ggg,hhh,iii,jjj,kkk,lll,mmm,nnn,ooo,ppp,qqq,rrr,sss,ttt,uuu,vvv,www,xxx,yyy,zzz'
return alph.split(',')
def isFold(x):
return os.path.isdir(x)
def splitIt(x,y):
if str(y) in str(x):
return x.split(y)
return False
def removeLast(x,y):
if x.replace(x[0:-len(y)],'') == y:
return x[0:-len(y)]
return x
def splitNum(x,spl):
return len(x.split(spl))
def createPath(x,y):
x = eatOuterMod(x,[slash,' ',''])
y = eatInnerMod(y,[slash,' ',''])
return x+slash+y
def getTime():
return time.time()
def eatInnerMod(x,ls):
if strInList(x,ls) != False:
x = strInList(x,ls)
return x
def eatOuterMod(x,ls):
if strInListRev(x,ls) != False:
x = strInListRev(x,ls)
return x
def isLs(x):
if type(x) is list:
return True
return False
def strInList(x,ls):
if ifOverZero(x) == True:
if x[0] in ls:
return x[1:]
return False
def strInListRev(x,ls):
if ifOverZero(x) == True:
if x[-1] in ls:
return x[:-1]
return False
def ifOverZero(x):
if len(x) >1:
return True
return False
def displayFiles(x):
exit = False
n = x
avoid = True
#avoid = boolAsk("avoid hidden?")
while exit != True:
x = x.split(' ')[0]
foldList = os.listdir(x)
if avoid == True:
foldList = isTypeFile('.py',x,removeFromList(foldList,'.',0))
ls = []
lsGet = []
for i in range(0,len(foldList)):
ls.append(allSizeDays(x,foldList,i))
lsGet.append(x)
ask = create_ask(ls,'current Directory '+str(x)+'\nwhich file would you like to use?')
ask = str(ask.split(' ')[0])
if ask == "exit":
exit == True
elif ask == "back":
n = buildToSplitLast(n,slash)
elif ask == "open":
openFileExplorer(x)
elif ask == "old":
return getFolder(x)
elif ask == "custom":
n = str(fileAsk())
if x == 'exit':
return 'exit'
elif str(ask) in foldList:
n = n+slash+ask
else:
n = n+slash+ask
if isFile(n) == True:
if boolAsk(fileInputString(splitTo(n,slash,-1))) == False:
n = buildToSplitLast(n,slash)
else:
return x,n
x = n+slash
displayFiles(home_it())