-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfolderlist.txt
More file actions
125 lines (113 loc) · 4.99 KB
/
Copy pathfolderlist.txt
File metadata and controls
125 lines (113 loc) · 4.99 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
param (
[switch]$list = $false,
[string]$ead = "..\FolderListOutput.txt"
)
function OutputMarkup ($spacer, $intitle, $insize, $incount) {
Write-Output "$spacer`t<did>`n"
Write-Output "$spacer`t`t<unittitle>$intitle</unittitle>`n"
Write-Output "$spacer`t`t<physdesc>`n"
Write-Output "$spacer`t`t`t<extent altrender=""materialtype spaceoccupied"">$insize</extent>`n"
Write-Output "$spacer`t`t`t<extent altrender=""carrier"">$incount electronic files</extent>`n"
Write-Output "$spacer`t`t</physdesc>`n"
Write-Output "$spacer`t</did>"
}
function GetSize ($invalue) {
if ($list -eq $true) {
if ($invalue -lt 1KB) {$outvalue = "{0:f2} B" -f ($invalue)}
if ($invalue -eq $null) {$outvalue = "0.00 B"}
if ($invalue -ge 1KB -and $invalue -lt 1MB) {$outvalue = "{0:f2} KB" -f ($invalue / 1KB)}
if ($invalue -ge 1MB -and $invalue -lt 1GB) {$outvalue = "{0:f2} MB" -f ($invalue / 1MB)}
if ($invalue -ge 1GB -and $invalue -lt 1TB) {$outvalue = "{0:f2} GB" -f ($invalue / 1GB)}
if ($invalue -ge 1TB) {$outvalue = "{0:f2} TB" -f ($invalue / 1TB)}
} else {
if ($invalue -lt 1KB) {$outvalue = "{0:f2} bytes" -f ($invalue)}
if ($invalue -eq $null) {$outvalue = "0.00 bytes"}
if ($invalue -ge 1KB -and $invalue -lt 1MB) {$outvalue = "{0:f2} kilobytes" -f ($invalue / 1KB)}
if ($invalue -ge 1MB -and $invalue -lt 1GB) {$outvalue = "{0:f2} megabytes" -f ($invalue / 1MB)}
if ($invalue -ge 1GB -and $invalue -lt 1TB) {$outvalue = "{0:f2} gigabytes" -f ($invalue / 1GB)}
if ($invalue -ge 1TB) {$outvalue = "{0:f2} terabytes" -f ($invalue / 1TB)}
}
return $outvalue
}
$file = $null
$output = $null
$outpart = $null
$basePath = '.'
$baseFolder = Get-Item $basePath
$subFolders = Get-ChildItem $basePath -Depth 0 -Directory
ForEach ($folder in $subFolders) {
$folderSize = (Get-Childitem -Path $folder.Name -File -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum
$folderCount = (Get-Childitem -Path $folder.Name -File -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Count
$outpart = GetSize($folderSize)
if ($list -eq $true) {
$output = "$folder, $outpart ($folderCount files)"
#Write-Output $output
$file = "$file$output`n"
} else {
$output = OutputMarkup "" $folder $outpart $foldercount
$file = "$file<c01 level=""file"">`n"
$file = "$file$output`n"
}
$subSubFolders = Get-ChildItem -Path $folder.Name -Depth 0 -Directory
ForEach ($folder2 in $subSubFolders) {
$folderSize = (Get-Childitem -Path $folder2.FullName -File -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum
$folderCount = (Get-Childitem -Path $folder2.FullName -File -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Count
$outpart = GetSize($folderSize)
if ($list -eq $true) {
$output = "- $folder2, $outpart ($folderCount files)"
$file = "$file$output`n"
} else {
$output = OutputMarkup "`t" $folder2 $outpart $foldercount
$file = "$file`t<c02 level=""file"">`n"
$file = "$file$output`n"
$file = "$file`t</c02>`n"
}
}
$folderSize = (Get-Childitem -Path $folder.Name -File -Depth 0 -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum
$folderCount = (Get-Childitem -Path $folder.Name -File -Depth 0 -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Count
if ($subSubFolders -ne $null) {
$outpart = GetSize($folderSize)
$output = "- Additional files, $outpart ($folderCount files)"
if ($folderCount -gt 0) {
if ($list -eq $true) {
$file = "$file$output`n"
} else {
$output = OutputMarkup "`t" "Additional files" $outpart $foldercount
$file = "$file`t<c02 level=""file"">`n"
$file = "$file$output`n"
$file = "$file`t</c02>`n"
}
}
}
if ($list -ne $true) {
$file = "$file</c01>`n"
}
}
$folderSize = (Get-Childitem -Path $basePath -File -Depth 0 -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Sum
$folderCount = (Get-Childitem -Path $basePath -File -Depth 0 -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue).Count
$outpart = GetSize($folderSize)
$output = "Additional files, $outpart ($folderCount files)"
if ($folderCount -gt 0) {
if ($list -eq $true) {
$file = "$file$output`n"
} else {
$output = OutputMarkup "" "Additional files" $outpart $foldercount
$file = "$file<c01 level=""file"">`n"
$file = "$file$output`n"
if ($list -ne $true) {
$file = "$file</c01>`n"
}
}
}
if ($list -eq $true) {
Write-Output $file
} else {
if ($ead -eq $true) {
$ead = "..\FolderListOutput.txt"
}
Write-Output "Written to $ead."
Write-Output $file | Out-File -FilePath $ead
}
if ($list -eq $false -and ($ead -eq $false -or $ead -eq $true)) {
Write-Output "Program requires either -list parameter or -ead parameter with file name."
}