-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask8.psm1
More file actions
51 lines (47 loc) · 1.5 KB
/
task8.psm1
File metadata and controls
51 lines (47 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<#
Рекурсивные функции обхода дерева каталогов (три отдельных задания)
#>
function DirInf {
param (
[System.IO.FileInfo] $Path = "."
)
$DirectoriesCount = (Get-ChildItem $Path -Directory | Measure-Object).Count
$FilesCount = (Get-ChildItem $Path -File | Measure-Object).Count
return @{
"DirectoriesCount" = $DirectoriesCount;
"FilesCount" = $FilesCount;
}
}
function CurDirInf {
param (
[System.IO.FileInfo] $Path = ".",
[int16] $DepthLevel = 0
)
$DirectoryName = $(Resolve-Path $Path).Path
$Offset = ""
for ($Depth = 0; $Depth -lt $DepthLevel; $Depth++) {
$Offset += " "
}
return "$Offset $DepthLevel $DirectoryName"
}
function GoDirs {
param (
[string] $Path = ".",
[int16] $DepthLevel = 0
)
$DirectoryInfo = DirInf -Path $Path
$DirectoryOutput = `
"$(CurDirInf -Path $Path -DepthLevel $DepthLevel)" `
+ " | Dirs - $($DirectoryInfo.DirectoriesCount)" `
+ " | Files - $($DirectoryInfo.FilesCount)"
Write-Host $DirectoryOutput
$SubDirectories = Get-ChildItem $Path -Directory -Name
foreach ($SubDirectory in $SubDirectories) {
$SubDirectoryPath = Join-Path $Path $SubDirectory
$SubDirectoryDepthLevel = $DepthLevel + 1
GoDirs -Path $SubDirectoryPath -DepthLevel $SubDirectoryDepthLevel
}
}
Export-ModuleMember DirInf
Export-ModuleMember CurDirInf
Export-ModuleMember GoDirs