-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplitB4U.py
40 lines (30 loc) · 1.18 KB
/
SplitB4U.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
import tkinter as tk
from tkinter import filedialog
def selectFile():
File=filedialog.askopenfilename(
title="Selecteer het B4U File",
filetypes=[("B4U Bestanden","*.b4u"),("Alle bestanden","*.*")]
)
if File:
return File
def createFiles(original, new, rowsPerFile):
with open(original, 'r', encoding='utf-8') as f:
lines = f.readlines()
header = lines.pop(0)
footer = lines.pop()
totalFiles = (len(lines) // rowsPerFile) + 1
for i in range(totalFiles):
fileLines = lines[i * rowsPerFile: (i + 1) * rowsPerFile]
fileLines.insert(0, header)
fileLines.append(footer)
output_file = f"{new}_{i + 1}.b4u"
with open(output_file, 'w', encoding='utf-8') as f_out:
f_out.writelines(fileLines)
print(f"File created: {output_file}")
original = selectFile()
rowsPerFile = input ("Hoeveel regels moeten er per bestand worden gegenereerd? ")
rowsPerFile = int(rowsPerFile)
lastSlashIndex = original.rfind('\\')
lastDotIndex = original.find('.', lastSlashIndex)
new = original[lastSlashIndex + 1:lastDotIndex]
createFiles(original, new, rowsPerFile)