-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfspl.py
More file actions
67 lines (42 loc) · 2.02 KB
/
Copy pathfspl.py
File metadata and controls
67 lines (42 loc) · 2.02 KB
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
import os
import math
def file_splitter():
file_path = input("File path? ").strip()
output_path = input("Output path and base name? ").strip()
split_count = input("Split into N files? (1-10): ").strip()
ignore_input = input("Ignore/Erase? (comma-separated, or leave empty): ").strip()
ignore_list = [i.strip() for i in ignore_input.split(",")] if ignore_input else []
try:
n = int(split_count) if split_count else 1
n = max(1, min(10, n))
except ValueError:
n = 1
if not os.path.exists(file_path):
print(f"Error: File '{file_path}' not found.")
return
try:
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
content = f.read()
if ignore_list:
print("Cleaning content...")
for word in ignore_list:
content = content.replace(word, "")
content = " ".join(content.split())
total_len = len(content)
chunk_size = math.ceil(total_len / n)
base_name, ext = os.path.splitext(output_path)
if not ext: ext = ".txt"
print(f"Splitting into {n} parts...")
for i in range(n):
start = i * chunk_size
end = start + chunk_size
part_content = content[start:end]
part_name = f"{base_name}_{i+1}{ext}"
with open(part_name, "w", encoding="utf-8") as f:
f.write(part_content)
print(f"Saved: {part_name} ({len(part_content)} chars)")
print("\nAll done!")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
file_splitter()