-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOldWritePathsToContent.ps1
More file actions
123 lines (101 loc) · 2.57 KB
/
OldWritePathsToContent.ps1
File metadata and controls
123 lines (101 loc) · 2.57 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
Set-Location $PSScriptRoot
Clear-Host
function Write-List
{
param
(
[Array]$list
)
for($i = 0; $i -lt $list.Count; $i += 1)
{
Write-Host "$($i)`t: $($list[$i])"
}
}
function Check-AdditionalDirectories
{
param
(
[System.IO.FileInfo]$currentPath,
[System.IO.FileInfo]$filePath
)
$checkItOut = Get-Content $filePath -Encoding UTF8
$filePathlist = $checkItOut.Split("`n")
$allFiles = @()
Write-List $filePathlist
foreach($path in $filePathlist)
{
Set-Location -LiteralPath $path
Write-Host "Import from`t: $($path)"
$allFilesLocal = Get-ChildItem $Directory -File -Name -Recurse
for($i = 0; $i -lt $allFilesLocal.Count; $i++)
{
$allFilesLocal[$i] = "$($path)$($allFilesLocal[$i])"
}
Write-Host "Fetched : $($allFilesLocal.Count)"
$allFiles += $allFilesLocal
Set-Location $currentPath
}
Set-Location $currentPath
return $allFiles
}
function Test-StringAgainstRegexList {
param(
[string]$inputString,
[string[]]$regexList
)
$matchFound = $false
foreach ($regex in $regexList) {
if ($inputString -cmatch $regex) {
$matchFound = $true
Write-Host "Not mathced by `"$($regex)`": $($file)"
break
}
}
return -not $matchFound
}
function Parse-Ignore
{
param
(
[System.IO.FileInfo]$IgnoreFilePath,
[string[]]$allFiles
)
$ignorePatterns = Get-Content -LiteralPath $IgnoreFilePath -Encoding UTF8
$ignorePatternList = $ignorePatterns.Split("`n")
Write-List $ignorePatternList
$filteredFiles = @()
foreach ($file in $allFiles)
{
if(Test-StringAgainstRegexList -inputString $file -regexList $ignorePatternList)
{
$filteredFiles += $file
}
}
return $filteredFiles
}
function Write-FileSize
{
param(
[Int64]$Size
)
[Int64]$Bytes = $Size % 1KB
[Int64]$KBytes = ($Size / 1KB) % 1KB
[Int64]$MBytes = ($Size / 1MB) % 1KB
[Int64]$GBytes = ($Size / 1GB) % 1TB
Write-Host "Size of file(s): $($GBytes) GB $($MBytes) MB $($KBytes) KB $($Bytes) B"
}
$location = Get-Location
$allFiles = Check-AdditionalDirectories $location.Path "pathToCheckItOut.txt"
$files = Parse-Ignore "ignore.txt" $allFiles
New-Item "content.txt" -Force
$totalSize = 0
$filePath = ""
foreach($file in $files)
{
$prop = Get-Item $file
$totalSize += $prop.Length
$resFilePath = $file -replace "\\", "/"
$resFilePath >> "content.txt"
}
Write-FileSize $totalSize
Pause