Skip to content

Instantly share code, notes, and snippets.

@DoganM95
Last active May 14, 2021 16:47
Show Gist options
  • Save DoganM95/ab59da144511b5f0348079ce60ed2f10 to your computer and use it in GitHub Desktop.
Save DoganM95/ab59da144511b5f0348079ce60ed2f10 to your computer and use it in GitHub Desktop.
FreeFileSync-missing-folder-creator
[xml]$xml = Get-Content "C:\Users\$env:UserName\OneDrive\Documents\BatchRun.ffs_batch"
$lefts = Select-Xml "//Left" $xml
$rights = Select-Xml "//Right" $xml
$allPaths = New-Object System.Collections.ArrayList;
$lefts | ForEach-Object { $allPaths.Add( $_.Node.'#text') | out-null }
$rights | ForEach-Object { $allPaths.Add( $_.Node.'#text') | out-null }
$created = New-Object System.Collections.ArrayList;
$skipped = New-Object System.Collections.ArrayList;
foreach ($pathItem in $allPaths) {
if (!(Test-Path -Path $pathItem)) {
New-Item -ItemType directory -Path $pathItem;
$created.Add($pathItem) | out-null;
}
else {
$skipped.Add($pathItem) | out-null;
}
}
if ($created.Count -gt 0) {
Write-Host "Created non-existing folders:" -ForegroundColor Green;
$created.ForEach( { Write-Host $_ });
}
if ($skipped.Count -gt 0) {
Write-Host "Skipped existing folders:" -ForegroundColor Yellow;
$skipped.ForEach( { Write-Host $_ });
}
Write-Host "Press any key to exit..."
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment