-
Notifications
You must be signed in to change notification settings - Fork 2
/
poll_and_move_files.ps1
52 lines (45 loc) · 1.34 KB
/
poll_and_move_files.ps1
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
param( $sourceFileList = "",
$newDestination = ""
)
$lineAmount = (Get-Content $sourceFileList).Count - 1
$arrayFromFile = Get-Content $sourceFileList | Select -Skip 1
[array]$missingFiles;
$scriptName = ([System.IO.Path]::GetFileNameWithoutExtension($sourceFileList))
$Currentdate = Get-Date -Format('ddMMyyyyHHmm')
$LogFolderPath = (Get-Content $sourceFileList | Select-Object -First 1)
$LogFile = $LogFolderPath + $scriptName + "_" + $Currentdate + ".log"
echo $lineAmount
function pollFiles{
[int]$testnum = 0;
for($i = 0; $i -lt $lineAmount; $i++){
$result = Test-Path $arrayFromFile[$i]
if($result -eq $True)
{
Write-Output $i
Write-Output $arrayFromFile[$i] " exists"
$testnum++
}
else {
[array]$missingFiles += $arrayFromFile[$i]
Write-Output "Missing " $arrayFromFile[$i]
}
}
if ($testnum -eq $lineAmount){
moveFiles;
}
else{logErrors;}
}
function moveFiles{
for($j = 0; $j -lt $lineAmount; $j++){
Move-Item -Path $arrayFromFile[$j] -Destination $newDestination
}
}
function logErrors{
echo $LogFile
Write-Output "Missing: " $missingFiles "´n" $Error > $LogFile
throw "File Missing";
}
function main{
pollFiles;
}
main;