-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit4x.ps1
More file actions
55 lines (48 loc) · 1.37 KB
/
split4x.ps1
File metadata and controls
55 lines (48 loc) · 1.37 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
param (
[Parameter(Mandatory=$true)]
[string]$inFile = $argv[0],
$MaxLength = 210
)
# Define the file path
#$file = "path_to_your_file.txt"
# Read the file content
$content = (Get-Content -Path $infile -Raw) -replace "`r`n", ""
# Define the maximum length of each piece
$maxLength = $MaxLength
# Initialize an empty array to hold the pieces
$pieces = @()
# While there is still content left
while ($content.Length -gt 0) {
# If the remaining content is shorter than the maximum length
if ($content.Length -le $maxLength) {
# Add the remaining content to the pieces array
$pieces += $content
# Clear the content
$content = ""
} else {
# Find the last space within the maximum length
$lastSpace = $content.Substring(0, $maxLength).LastIndexOf(" ")
# Add the piece up to the last space to the pieces array
$pieces += $content.Substring(0, $lastSpace)
# Remove the piece from the content
$content = $content.Substring($lastSpace + 1)
}
}
$numPieces = $pieces.Length
$num = 1
foreach ($p in $pieces) {
if ($num -gt 1) {
$prefix = ".."
} else {
$prefix = ""
}
if ($num -lt $numPieces) {
$suffix = ".."
} else {
$suffix = ""
}
Write-Output "$($num)/$($numPieces) `"$prefix$p$suffix`""
$num += 1
}
# Output the pieces
#$pieces