Add OnBeforeTraverse and OnAfterTraverse to Invoke-TraverseDirectory
Closed this issue · 1 comments
plastikfan commented
This allows the client to provide a callback to be invoked just before (OnBeforeTraverse
) a directory has been traversed and then afterwards (OnAfterTraverse
). But we only invoke these, is the directory being traverse contains sub-directories; ie it is not a leaf directory (any place that invokes Get-ChildItem, should be wrapped with OnBefore/OnAfer).
eg, currently:
# Now perform start of recursive traversal
#
[System.IO.DirectoryInfo[]]$directoryInfos = Get-ChildItem -Path $Path `
-Directory | Where-Object { $Condition.InvokeReturnAsIs($_) }
if ($directoryInfos) {
$directoryInfos | Invoke-ForeachFsItem -Directory -Block $adapter `
-Exchange $Exchange -Condition $Condition -Summary $Summary;
}
would become:
# Now perform start of recursive traversal
#
[System.IO.DirectoryInfo[]]$directoryInfos = Get-ChildItem -Path $Path `
-Directory | Where-Object { $Condition.InvokeReturnAsIs($_) }
if ($directoryInfos.Count -gt 0) {
# Invoke-OnBeforeTraverse
}
if ($directoryInfos) {
$directoryInfos | Invoke-ForeachFsItem -Directory -Block $adapter `
-Exchange $Exchange -Condition $Condition -Summary $Summary;
}
if ($directoryInfos.Count -gt 0) {
# Invoke-OnAfterTraverse
}
plastikfan commented
This would allow a client to perform once per traversal level functionality, eg check the existence of a custom options file, or whatever else is required.