Skip to content

Instantly share code, notes, and snippets.

@sowderca
Last active March 5, 2021 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sowderca/21c6962ab111a22ac7cef07a0fc9e9c2 to your computer and use it in GitHub Desktop.
Save sowderca/21c6962ab111a22ac7cef07a0fc9e9c2 to your computer and use it in GitHub Desktop.
flat directory file dependency solution
#!/usr/bin/env pwsh
#Requires -Version 7
param([string] $path);
Push-Location -Path $path;
function order([string] $Path) {
[Collections.Stack] $stack = [Collections.Stack]::new();
foreach ($file in (Get-ChildItem -Path $Path -Filter '*.txt')) {
[void] $stack.Push($file.Name);
$file | Get-Content | ForEach-Object {
[string]::IsNullOrEmpty($_) ? (&{return}) : (order($_));
}
}
return $stack.ToArray();
}
order -Path $path | Select-Object -Unique;
Pop-Location;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment