forked from Leeds-ABSL/ABSL_pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEM_Pull_FIles.ps1
65 lines (46 loc) · 2.44 KB
/
EM_Pull_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
53
54
55
56
57
58
59
60
61
62
63
64
65
# Script for the EM group to copy files off the local hard-drive of the data-gathering
# PCs to an external hard-drive. This hard-drive will have a fixed drive letter.
function EM_Pull_Files {
# Recursively get all the child items in the source directory where the last write
# time is more than 10 minutes ago, then move that to the target directory.
# First check if drive G: exists. If not, map it using the supplied credentials
if (!(Test-Path G:))
{
$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("G:", "\\gatancustomer\DoseFractions", $false, "gatancustomer\valuedgatancustomer", "`$admin")
}
# Create a variable that defines the source directory
$source = "G:\"
# Create a variable that defines the target directory
$destination = "D:\DoseFractions\"
# Now select all files that were last written to more than 10 minutes ago and copy them
# to the target destination. As we're being selective about files using Get-ChildItem,
# the Copy-Item command won't preserve the directory structure, so we have to run tests
# and create the correct directory structure if necessary.
# Create a variable that will hold the output from a Get-ChildItem call
$items = Get-ChildItem $source -Recurse -Filter "*_Data_*.mrc" | Where {$_.LastWriteTime -lt (Date).AddMinutes(-10)}
# Now run test commands on each item called from the Get-ChildItem commnad above
foreach ($item in $items)
{
# Create a variable to hold the name of the target directory (this takes the directory
# name of the source file and replaces the source root directory info with the target
# root directory info
$dir = $item.DirectoryName.Replace($source,$destination)
# Create a variable to hold the name of the target file name (this takes the full file
# name of the source file and replaces the source root directory info with the target
# root directory info
$target = $item.FullName.Replace($source,$destination)
# Test if the target directory exists. If not, create it
if (!(test-path($dir))) { mkdir $dir }
# Test if the target file exists. If not, copy the source file across
if (!(test-path($target)))
{
Move-Item -path $item.FullName -destination $target -force
}
}
#Get-ChildItem -recurse $source |
#Where {$_.LastWriteTime -lt (Date).AddMinutes(-10)} |
#Copy-Item -Destination $destination -Recurse -Force
} # End of function EM_Pull_Files
# Run the function EM_Pull_Files
EM_Pull_Files