Here is an example of the PowerShell script is invoked:
.\Folder.ps1 -FolderName C:\Blog
Here is the PowerShell to traverse a given folder:
Param (
[string] $folderName = $PSScriptRoot
)
class Folder
{
[void] Traverse([string] $folderName)
{
$entities = Get-ChildItem `
-Path $folderName `
-ErrorAction SilentlyContinue `
-Force
foreach ($entry in $entities) {
if ($entry -is [System.IO.DirectoryInfo]) {
Write-Host 'Directory:' $entry.FullName
$this.Traverse($entry.FullName)
}
else { # if ($entry -is [System.IO.FileInfo])
Write-Host 'File:' $entry.FullName
}
}
}
}
[Folder] $folder = [Folder]::new()
$folder.Traverse($folderName)
No comments :
Post a Comment