-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrrr.py
108 lines (84 loc) · 3.14 KB
/
rrr.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
#!/usr/bin/python3
import os
import shutil
from zipfile import ZipFile
import zipfile
class minklasse():
def __init__(self, mappecounter, udFolder):
self.mappecounter = mappecounter
self.unZipMappeCount = 0
self.udFolder = udFolder
self.tempFolder = os.path.join('/mnt/minlvhdd/Xmindisk/', 'temp')
if not os.path.isdir(self.tempFolder):
os.mkdir(self.tempFolder)
def naestefil(self)->int:
self.mappecounter += 1
return f'{self.mappecounter}'
def naesteUnzipMappe(self):
self.unZipMappeCount += 1
return os.path.join( self.tempFolder, f'Z{self.unZipMappeCount}')
def sorter(self, minfil)-> None:
if (minfil[-4:] == '.txt'):
if minfil[-5:] == '8.txt':
targetFolder = 'utf'
targetFile = self.naestefil() +'8.txt'
else:
targetFolder = 'txt'
targetFile = self.naestefil() +'.txt'
elif minfil.endswith('.pdf'):
targetFolder = 'pdf'
targetFile = self.naestefil() + '.pdf'
elif minfil.endswith('.mp3'):
targetFolder = 'mp3'
targetFile = self.naestefil() +'.mp3'
else:
targetFolder = 'andrefiler'
targetFile = self.naestefil() + minfil[-4:]
# targetFolder = os.path.join( sortfolder('andrefiler/'), str(str(self.naestefil()) + fileName[-4:]))
target = os.path.join( self.udFolder, targetFolder, targetFile)
print(f'kopierer {minfil} til {target}')
try :
shutil.copy( minfil, target)
except IOError:
print('kopiering ikke mulig')
def myunzip(self, zipfil ):
print(f'{zipfil=}')
unzipMappe = self.naesteUnzipMappe()
if not os.path.isdir(unzipMappe):
os.mkdir(unzipMappe)
with ZipFile(zipfil, 'r') as zipObject:
try:
zipObject.extractall(unzipMappe)
except ValueError :
print('udpakning ikke ok')
return unzipMappe
def gennemGaaMappe(self, mappeNavn) :
for denneMappe, _, filnavne in os.walk(mappeNavn):
print(f'{denneMappe=}')
for fil in filnavne:
pFil = os.path.join( denneMappe, fil )
print(fil)
if fil.endswith('.zip'):
nyMappe = self.myunzip( pFil )
self.gennemGaaMappe(nyMappe)
# Slet nyMappe
else :
self.sorter( pFil )
def mkSortDir(folder):
folder = os.path.join( highestsortfolder, folder )
if not os.path.isdir(folder):
os.mkdir(folder)
if __name__ == '__main__':
pwd = '/mnt/minlvhdd/Xmindisk/'
highestfolder = os.path.join( pwd, 'gutenbergzip/' )
highestsortfolder = os.path.join(pwd, 'output/')
# lav mappe struktur
if not os.path.isdir(highestsortfolder):
os.mkdir(highestsortfolder)
mkSortDir('utf')
mkSortDir( 'txt' )
mkSortDir( 'pdf' )
mkSortDir( 'mp3' )
mkSortDir( 'andrefiler' )
system1 = minklasse(100, highestsortfolder)
system1.gennemGaaMappe(highestfolder)