-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_020_Send_Copy.ps1
More file actions
68 lines (61 loc) · 2.42 KB
/
_020_Send_Copy.ps1
File metadata and controls
68 lines (61 loc) · 2.42 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
. ($PSScriptRoot + "\_Functions.ps1")
$bitsTransferIsCompatible = $PSVersionTable.PSEdition -eq "Desktop"
if($bitsTransferIsCompatible){
Import-Module BitsTransfer
}
[xml]$config = Get-Content -Path ($PSScriptRoot + "\" + "Config.xml")
$unhandledItems = @()
$operationType = "SendCopy"
$sourceFolder = $config.Root.Send.TargetZipFolder
$targetFolder = $config.Root.Send.TargetCopyFolder
$errorsPath = ($PSScriptRoot + "\" + "log_" + $operationType + ".txt")
$deletionReadyPath = ($PSScriptRoot + "\" + "deletion_ready_" + $operationType + ".txt")
$progressFilePath = ($PSScriptRoot + "\" + "InProgress_" + $operationType + ".txt")
$zippedFilenameStartsWith = "_data"
$zippedFilenameExtension = ".7z"
$progressStartText = "## Begin ##"
$progressEndText = "## End ##"
### Get last file to not be fully processed ###
$progress = Get-Progress $progressFilePath
$beginFile = $progress[0]
$beginIndex = $progress[1]
$items = Get-ChildItem $sourceFolder
$i = [int]$beginIndex
foreach ($item in $items){
### Skip file if already processed ###
if($beginFile){
if($beginFile -ne $item.Name){
Write-Output ("Skipping file: " + $item.Name)
continue
}
}
$beginFile = ""
if($item.Name.StartsWith($zippedFilenameStartsWith) -and $item.Name.EndsWith($zippedFilenameExtension)){
$archiveFilename = $item.Name
$archiveTargetPath = ($targetFolder + "\" + $archiveFilename)
try
{
Write-Output ("Copying file: " + $item.Name)
Set-ProgressStarted $progressFilePath $progressStartText $item.Name $i
$stopwatch = [system.diagnostics.stopwatch]::StartNew()
if($bitsTransferIsCompatible){
Start-BitsTransfer -Source ($sourceFolder + "\" + $item.Name) -Destination $archiveTargetPath -Description ("Copying file: " + $item.Name + " to location: " + $archiveTargetPath) -DisplayName "File copy operation" -Verbose
} else {
Copy-Item -Path ($sourceFolder + "\" + $item.Name) -Destination $archiveTargetPath -Verbose
}
Write-Output ("Time it took to complete process: " + $stopwatch.Elapsed)
Set-ProgressCompleted $progressFilePath $progressEndText $deletionReadyPath ($sourceFolder + "\" + $item.Name) $operationType
}
catch
{
$exceptionMessage = Get-ExceptionMessage ("Was not able to copy file: " + $item.Name)
Write-Output $exceptionMessage
$unhandledItems += $exceptionMessage
}
$i = $i + 1
[System.GC]::Collect()
}
}
Remove-Item -Path $progressFilePath
Write-LogInfo $unhandledItems $errorsPath
[System.GC]::Collect()