Powershell разбить массив на маленькие файлы
Есть массив такого вида:
string1
string2
string3
...
string100
Необходимо создать текстовые файлы с этими строчками, в каждом файле например по 10 строк. Не могу сообразить, как это сделать?
Ответы (1 шт):
Автор решения: Alexandr Fatalny
→ Ссылка
$arr = @()
$groupByCount = 7;
$rootFileScripts = "D:\scripts\";
$fileRootName = "defaultLogOutput";
$fileExtension = ".txt";
for($index = 0; $index -lt $arr.length; $index += $groupByCount) {
for ($jIndex = 0; $jIndex -lt $groupByCount; $jIndex++) {
$fileName = $rootFileScripts + $fileRootName + $index + $fileExtension;
echo $arr[$index+$jIndex] | Out-File $fileName -Append;
}
}