-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilesio.py
495 lines (463 loc) · 10.9 KB
/
Filesio.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
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
##############################################################################
## File operations ##
##############################################################################
import os
import time
import tkinter as tk
import pandas as pd
from configparser import ConfigParser
def file_ext(path):
try:
if os.path.isfile(path):
ext = os.path.splitext(path)[1].lower()
if ext:
return ext
else:
return ''
else:
return ''
except Exception as err:
print('In file_ext ', err)
return False
def file_type(path):
#finish this!!!!!
try:
if os.path.isfile(path):
ext = os.path.splitext(path)[1].lower()
if ext:
pass
except:
pass
def file_attr(p, dir=False):
try:
mdate = time.strftime('%d.%m.%Y %H:%M', time.localtime(os.path.getmtime(p)))
except Exception as er:
#print('In file_attr mdate', er)
mdate = ""
if not dir:
try:
size = os.stat(p).st_size
except:
size = None
#ext = file_ext(p)
else:
size = None
#imgname = "self.img" + ptype.replace(" file", "")
return mdate, size
tree.item(id, image=self.imgMisc)
if (numrow % 2 == 0): tree.item(id, tags=("even",))
numrow += 1
def get_exts():
file = 'Config.ini'
config = ConfigParser()
config.read(file)
extdic = dict(config.items('File extensions'))
return extdic
def check_extfile():
'''check file extension'''
file = 'Config.ini'
if not os.path.isfile(file) or os.stat(file).st_size == 0:
with open(file, 'w', encoding='utf-8') as f:
f.write(fileext())
def open_store(name, new=False):
store = pd.HDFStore(name, format='f', mode='a', complib='zlib', complevel=9)
return store
def get_imgs(path):
'''Gets dictionary containing icons'''
imgcache = { os.path.splitext(filename)[0] : tk.PhotoImage(
file = os.path.join(path, filename)) for filename in os.listdir(path) }
return imgcache
def month_name(n):
month = {
1:'January', 2:'February',
3:'March', 4:'April',
5:'May', 6:'June',
7:'July', 8:'August',
9:'September', 10:'October',
11:'November', 12:'December'
}
return month[n]
#Customized os.walk function
def walk_folder(top, topdown=True, onerror=None, followlinks=False):
dirs = []
try:
scandir_it = os.scandir(top)
entries = list(scandir_it)
except OSError as error:
if onerror is not None:
onerror(error)
return
for entry in entries:
try:
is_dir = entry.is_dir()
except OSError:
# If is_dir() raises an OSError, consider that the entry is not
# a directory, same behaviour than os.path.isdir().
is_dir = False
if is_dir:
dirs.append(entry.name)
if topdown:
yield dirs
# Recurse into sub-directories
islink, join = os.path.islink, os.path.join
for dirname in dirs:
new_path = join(top, dirname)
# Issue #23605: os.path.islink() is used instead of caching
# entry.is_symlink() result during the loop on os.scandir() because
# the caller can replace the directory entry during the "yield"
# above.
if followlinks or not islink(new_path):
yield from walk_folder(new_path, topdown, onerror, followlinks)
else:
# Yield after recursion if going bottom up
yield dirs
def walk_file(top, topdown=True, onerror=None, followlinks=False):
dirs = []
nondirs = []
try:
scandir_it = os.scandir(top)
entries = list(scandir_it)
except OSError as error:
if onerror is not None:
onerror(error)
return
for entry in entries:
try:
is_dir = entry.is_dir()
except OSError:
# If is_dir() raises an OSError, consider that the entry is not
# a directory, same behaviour than os.path.isdir().
is_dir = False
if is_dir:
dirs.append(entry.name)
else:
nondirs.append(entry.name)
yield nondirs
# Recurse into sub-directories
join = os.path.join
for dirname in dirs:
new_path = join(top, dirname)
yield from walk_file(new_path, topdown, onerror, followlinks)
def walk_full(top, known=[], hidden=False, skip=[], followlinks=False):
dirs = []
nondirs = []
try:
scandir_it = os.scandir(top)
entries = list(scandir_it)
except OSError as error:
return
for entry in entries:
try:
is_dir = entry.is_dir()
except OSError:
is_dir = False
if skip and entry.name not in skip:
if is_dir:
dirs.append(entry.name)
else:
ext = os.path.splitext(entry.name)[1]
if known and ext in known:
nondirs.append(entry.name)
elif not known:
nondirs.append(entry.name)
elif not skip:
if is_dir:
dirs.append(entry.name)
else:
if known and entry.name not in known:
nondirs.append(entry.name)
elif not known:
nondirs.append(entry.name)
yield top, dirs, nondirs
# Recurse into sub-directories
islink, join = os.path.islink, os.path.join
for dirname in dirs:
new_path = join(top, dirname)
yield from walk_full(new_path, known, hidden, skip, followlinks)
def fileext():
fileexts = '''[Skipped items]
showhiddenitems = 1
showonlyknownitems = 1
skiplisteditems = 1
[SkippedList]
[File extensions]
.3dm:CAD file
.3ds:CAD file
.3g2:Video file
.3ga:Audio file
.3gp:Video file
.3gpp:Video file
.7z:Archive file
.aac:Audio file
.accdb:Database file
.ai:Misc file
.aif:Audio file
.aifc:Audio file
.aiff:Audio file
.amr:Audio file
.apk:Archive file
.app:Misc file
.art:Image file
.arw:Image file
.asf:Video file
.asp:Website file
.aspx:Website file
.au:Audio file
.aup:Audio file
.avi:Video file
.azw:eBook file
.azw3:eBook file
.bat:Misc file
.bin:Misc file
.bmp:Image file
.bup:Database file
.bz2:Archive file
.c:Website file
.cab:Archive file
.caf:Audio file
.cbr:eBook file
.cda:Misc file
.cdr:Misc file
.cer:Website file
.cfg:Misc file
.cfm:Website file
.cgi:Misc file
.chm:Document file
.class:Misc file
.com:Misc file
.cpi:Video file
.cpl:Misc file
.cpp:Misc file
.cr2:Image file
.crdownload:Misc file
.crw:Image file
.crx:Archive file
.cs:Misc file
.csr:Website file
.css:Website file
.csv:Spreadsheet file
.dat:Misc file
.db:Database file
.dcm:Image file
.dds:Image file
.deb:Archive file
.dem:Misc file
.deskthemepack:Misc file
.divx:Video file
.djvu:Image file
.dll:Misc file
.dmg:Image file
.dmp:Misc file
.dng:Image file
.doc:Document file
.docm:Document file
.docx:Document file
.dot:Document file
.dotx:Document file
.drv:Misc file
.dtd:Misc file
.dwg:CAD file
.dxf:CAD file
.eml:Document file
.emz:Misc file
.eps:Misc file
.epub:eBook file
.exe:Application
.exr:Image file
.f4v:Video file
.fb2:eBook file
.fla:Misc file
.flac:Audio file
.flv:Video file
.fnt:Misc file
.fon:Misc file
.fpx:Image file
.gadget:Misc file
.gam:Misc file
.ged:Database file
.gif:Image file
.gpx:Misc file
.gsm:Audio file
.gz:Archive file
.gzip:Archive file
.h:Misc file
.h264:Video file
.hdr:Image file
.htm:Website file
.html:Website file
.hwp:Document file
.icns:Image file
.ico:Image file
.ics:Misc file
.iff:Audio file
.ifo:Video file
.img:Misc file
.indd:Misc file
.inf:Misc file
.ini:Misc file
.ipa:Misc file
.iso:Misc file
.ithmb:Image file
.itl:Database file
.jad:Misc file
.jar:Archive file
.java:Misc file
.jp2:Image file
.jpeg:Image file
.jpg:Image file
.js:Website file
.json:Website file
.jsp:Website file
.kar:Audio file
.key:Presentation file
.keychain:Misc file
.kml:Misc file
.kmz:Misc file
.lit:eBook file
.lnk:Misc file
.log:Document file
.lrf:eBook file
.lua:Misc file
.m:Misc file
.m2ts:Video file
.m3u:Document file
.m4a:Audio file
.m4p:Audio file
.m4r:Audio file
.m4v:Video file
.max:CAD file
.mbp:eBook file
.mdb:Database file
.mdf:Misc file
.mdi:Misc file
.mid:Audio file
.midi:Audio file
.mim:Misc file
.mkv:Video file
.mmf:Audio file
.mobi:eBook file
.mod:Video file
.mov:Video file
.mp2:Audio file
.mp3:Audio file
.mp4:Video file
.mpa:Audio file
.mpeg:Video file
.mpg:Video file
.mpga:Audio file
.msg:Document file
.msi:Application
.mswmm:Video file
.mts:Video file
.mxf:Video file
.nef:Image file
.nes:Misc file
.nfo:Misc file
.nrw:Image file
.obj:CAD file
.odg:Misc file
.odp:Presentation file
.ods:Spreadsheet file
.odt:Document file
.ogg:Audio file
.ogv:Video file
.oma:Audio file
.opf:eBook file
.opus:Audio file
.orf:Image file
.otf:Misc file
.oxps:Document file
.pages:Document file
.pcd:Image file
.pcx:Image file
.pdb:Database file
.pdf:Document file
.pes:Misc file
.php:Website file
.pict:Image file
.pif:Misc file
.pkg:Misc file
.pl:Misc file
.plugin:Misc file
.png:Image file
.pps:Presentation file
.ppsx:Presentation file
.ppt:Presentation file
.pptm:Presentation file
.pptx:Presentation file
.prc:eBook file
.ps:Misc file
.psd:Image file
.pspimage:Image file
.pub:Document file
.py:Misc file
.qcp:Audio file
.qt:Video file
.ra:Audio file
.ram:Audio file
.rar:Archive file
.rem:Misc file
.rm:Video file
.rom:Misc file
.rpm:Archive file
.rss:Website file
.rtf:Document file
.sav:Misc file
.sdf:Database file
.sfw:Image file
.sh:Misc file
.sitx:Archive file
.sln:Misc file
.sql:Database file
.srt:Video file
.svg:Misc file
.swf:Video file
.swift:Misc file
.sxw:Document file
.sys:Misc file
.tar:Archive file
.tar.gz:Archive file
.tax2014:Misc file
.tcr:eBook file
.tex:Document file
.tga:Image file
.tgz:Archive file
.thm:Image file
.tif:Image file
.tiff:Image file
.toast:Misc file
.torrent:Misc file
.ts:Video file
.ttf:Misc file
.txt:Document file
.uue:Misc file
.vb:Misc file
.vcd:Misc file
.vcf:Misc file
.vcxproj:Misc file
.vep:Video file
.vob:Video file
.vsd:Misc file
.wav:Audio file
.wbmp:Image file
.webm:Video file
.webp:Image file
.wlmp:Video file
.wma:Audio file
.wmf:Misc file
.wmv:Video file
.wpd:Document file
.wpg:Misc file
.wps:Document file
.wsf:Misc file
.xcf:Image file
.xcodeproj:Misc file
.xls:Spreadsheet file
.xlsx:Spreadsheet file
.xml:Document file
.xps:Document file
.xspf:Audio file
.yuv:Image file
.zip:Archive file
.zipx:Archive file'''
return fileexts