I'm trying to take files in existing sub-directories and create new directories, each containing six files within their current subdirectory. This is for use with a batch analysis tool that can only currently handle six files reliably and can only open directories. My code iterated through each subdirectory and created the appropriate number of new directories but didn't move any of the files.
Get-ChildItem -Directory | ForEach-Object {
$directory_count = 0;
$files = Get-ChildItem $_ -filter *.xml;
$curr_dir = $_;
$i = 0;
Write-Host "Working on $_.FullName"
foreach ($file in $files) {
if ($i -eq 6) {
$directory_count += 1;
$i = 0;
}
if (Test-Path ".\$curr_dir\$directory_count") {
}
else {
New-Item -ItemType Directory -Force -Path ".\$curr_dir\$directory_count";
}
Move-Item -Path $curr_file -Destination ".\$curr_dir\$directory_count";
$i += 1;
}
}