What Do You Mean I'm The Captain Of A Yandere Mercenary Company? - Chapter 535
# Đường dẫn tới thư mục chứa các thư mục chapter
$sourceDir = “C:UsersADMINDesktopWEBNOVEL” # Thay bằng đường dẫn thư mục chứa các thư mục như “Chapter 274”
# Duyệt qua từng thư mục trong thư mục gốc
Get-ChildItem -Path $sourceDir -Directory | ForEach-Object {
$folder = $_
$txtFiles = Get-ChildItem -Path $folder.FullName -File “*.txt”
if ($txtFiles) {
# Lấy dòng đầu tiên từ file .txt đầu tiên
$firstLine = Get-Content -Path $txtFiles[0].FullName -TotalCount 1
if ($firstLine) {
# Tìm vị trí của hai dấu cách liền nhau
$doubleSpaceIndex = $firstLine.IndexOf(” “)
if ($doubleSpaceIndex -ge 0) {
# Lấy từ đầu đến trước hai dấu cách
$chapterNameExtend = $firstLine.Substring(0, $doubleSpaceIndex).Trim()
} else {
# Nếu không có hai dấu cách, lấy toàn bộ dòng
$chapterNameExtend = $firstLine.Trim()
}
# Loại bỏ ký tự không hợp lệ trong tên thư mục
$chapterNameExtend = $chapterNameExtend -replace ‘[/:*?”<>|]’, ”
# Tạo tên mới: “Chapter X — Chapter Name Extend”
$newFolderName = “$($folder.Name) — $chapterNameExtend”
$newFolderPath = Join-Path -Path $sourceDir -ChildPath $newFolderName
# Đổi tên thư mục
Rename-Item -Path $folder.FullName -NewName $newFolderName
Write-Host “Đã đổi tên: $($folder.Name) -> $newFolderName”
}
} else {
Write-Host “Không tìm thấy file .txt trong: $($folder.Name)”
}
}
Write-Host “Hoàn tất đổi tên các thư mục!”
# (Tùy chọn) Nén thành file ZIP
# $outputZip = “C:pathtooutput.zip”
# Compress-Archive -Path “$sourceDir*” -DestinationPath $outputZip -Force
# Write-Host “Đã tạo file ZIP: $outputZip”