Files and Folders (PowerShell)
Jump to navigation
Jump to search
Directory Walker
A basic recursive function to walk through a directory tree
function Walk-Directory ($path = $pwd) {
# Get files/folders in current path
$items = Get-ChildItem $path
# Go through each file/folder in current path
foreach ($item in $items) {
if ($item.Attributes -contains "Directory") {
# Do something to every folder here (if you need to)
Walk-Directory $item.FullName # Drill down into directory
}
# Do something to every file here (if you need to)
$item.FullName
}
}
Walk-Directory "C:\Intel"