Цитата Busla:
вот как можно работать с кодом на iPad »
|
А что там? Не могли бы пояснить разницу «до» и «после» несведущему?
А что с моим вопросом про глобальную цель?
Как-то так (PowerShell):
Joiner.ps1
Код:

Param(
[System.String]$DestFile = 'outfile.txt'
[System.String]$SourceFolder = $pwd,
)
if(Test-Path -Path $SourceFolder -PathType Container) {
$cContent = Get-ChildItem -Path $SourceFolder -File -Recurse -Include '*.txt' -Exclude $DestFile | ForEach-Object -Process {
"[$(($_.FullName).Remove(0, $SourceFolder.Length + 1))]`r`n" + [System.IO.File]::ReadAllText($_.FullName, [System.Text.Encoding]::Unicode) + "`r`n"
}
[System.IO.File]::WriteAllLines((Join-Path -Path $SourceFolder -ChildPath $DestFile), $cContent, [System.Text.Encoding]::Unicode)
} else {
Write-Host "Can't find source folder [$SourceFolder]." -ForegroundColor Red
}
Именем результирующего файла по умолчанию является «outfile.txt», исходным каталогом по умолчанию — текущий каталог (могут быть переопределены заданием параметров при вызове скрипта).
Splitter.ps1
Код:

Param(
[System.String]$SourceFile = 'outfile.txt',
[System.String]$DestFolder = $pwd
)
if(Test-Path -Path $SourceFile -PathType Leaf) {
if(Test-Path -Path $DestFolder -PathType Container) {
$sContent = [System.IO.File]::ReadAllText($SourceFile, [System.Text.Encoding]::Unicode)
$oRegExp = New-Object -TypeName 'System.Text.RegularExpressions.Regex' -ArgumentList '\[(.+)\]\r\n([\s\S]*?)(?:\r\n){2}(?=\[.+\]|$)'
if($oRegExp.IsMatch($sContent)) {
$oRegExp.Matches($sContent) | ForEach-Object -Process {
$sCurrDestFile = Join-Path -Path $DestFolder -ChildPath $_.Groups[1].Value
$sCurrDestFolder = Split-Path -Path $sCurrDestFile -Parent
if(-not (Test-Path -Path $sCurrDestFolder -PathType Container)) {
New-Item -ItemType Directory -Path $sCurrDestFolder -Force | Out-Null
}
[System.IO.File]::WriteAllText($sCurrDestFile, $_.Groups[2].Value, [System.Text.Encoding]::Unicode)
}
} else {
Write-Host "Can't find any match in file [$SourceFile]." -ForegroundColor Red
}
} else {
Write-Host "Can't find destination folder [$DestFolder]." -ForegroundColor Red
}
} else {
Write-Host "Can't find source file [$SourceFile]." -ForegroundColor Red
}
Именем исходного файла по умолчанию является «outfile.txt», целевым каталогом по умолчанию — текущий каталог (могут быть переопределены заданием параметров при вызове скрипта).