Master Thesis Code
by Simon Moser
Loading...
Searching...
No Matches
getDataFromETHZ.ps1
Go to the documentation of this file.
1# Show nice ASCII ZHAW logo in Cyan
2Write-Host @"
3 ______ _ _ __ __
4 |___ /| | | | /\\ \ / /
5 / / | |__| | / \\ \ /\ / /
6 / / | __ | / /\ \\ \/ \/ /
7 / /__ | | | | / ____ \\ /\ /
8 /_____||_| |_|/_/ \_\\/ \/
9
10"@ -ForegroundColor Cyan
11
12# Show Header (Institute, Author, Date) in Yellow
13Write-Host @"
14Institute: Institute of Signal Processing and Wireless Communications
15Author: Simon Moser (moss)
16Date: 2024-07-09
17
18"@ -ForegroundColor Yellow
19
20# Inform the user about the script's purpose in Gray
21Write-Host @"
22This script copies the needed files from the ETHZ server to the local machine for further processing.
23
24"@ -ForegroundColor Gray
25
26
27# Source directories
28## Define source directories
29$sourceDirs = (Read-Host "Enter source directories (separated by comma)").Split(",")
30
31# Validate user input (remove white spaces, check if directories exist)
32$sourceDirs = $sourceDirs | ForEach-Object {
33 $thisDir = $_.Trim()
34 if (!(Test-Path -Path $thisDir)) {
35 Write-Host "Directory not found: $thisDir"
36 exit
37 }
38 $thisDir
39}
40
41# Output source directories for user to check
42Write-Host "Source directories:"
43$sourceDirs
44Write-Host ""
45
46# Target directory
47## Define target directory
48$targetDir = Read-Host "Enter target directory"
49
50# Validate user input (remove white spaces)
51$targetDir = $targetDir.Trim()
52
53## Output target directory for user to check
54Write-Host "Target directory: $targetDir"
55Write-Host ""
56
57## Create target directory if it doesn't exist
58if (!(Test-Path -Path $targetDir)) {
59
60 # get confirmation from user
61 $createDir = Read-Host "Target directory does not exist. Do you want to create it? (y/n)"
62 if ($createDir -eq "y") {
63 try {
64 New-Item -Path $targetDir -ItemType Directory > $null
65 Write-Host "Target directory created."
66 Write-Host ""
67 }
68 catch {
69 Write-Host "Error creating target directory. Exiting script."
70 exit
71 }
72 }
73 else {
74 Write-Host "Target directory not created. Exiting script."
75 exit
76 }
77}
78
79# Participant numbers
80## Define participant numbers
81$participantNumbers = (Read-Host "Enter participant numbers (separated by comma)").Split(",")
82
83# Output participant numbers for user to check
84Write-Host "Participant numbers:"
85$participantNumbers
86Write-Host ""
87
88# Loop through each participant number
89foreach ($participantNumber in $participantNumbers) {
90 Write-Host "Processing participant: $participantNumber"
91
92 # List of files that need to be copied (relative to the source directory)
93 $files_to_copy = @(
94 "\Processed\VICON\GaitSummary_YK\SonE_$participantNumber.mat",
95 "\Result\GaitSummaryIMU_SonE_$participantNumber.mat")
96
97 # Loop through each source directory
98 foreach ($sourceDir in $sourceDirs) {
99
100 # define source folder
101 $this_participant_source = $sourceDir + "\SonE_" + $participantNumber
102
103 # check if source folder exists
104 if (!(Test-Path -Path $this_participant_source)) {
105 Write-Host "Source folder not found: $this_participant_source"
106 continue
107 }
108
109 # define target folder
110 $this_participant_target = $targetDir + "\SonE_" + $participantNumber
111
112 # create target folder if it doesn't exist
113 if (!(Test-Path -Path $this_participant_target)) {
114 try {
115 New-Item -Path $this_participant_target -ItemType Directory > $null
116 }
117 catch {
118 Write-Host "Error creating directory: $this_participant_target, exiting script."
119 Read-Host "Press Enter to exit..."
120 exit
121 }
122 }
123
124 # add all files to the file list that match $this_participant_source + "\RawData\ZM\*.BIN"
125 $binary_files = Get-ChildItem -Path "${this_participant_source}\RawData\ZM\*.BIN"
126 foreach ($binary_file in $binary_files) {
127 $files_to_copy += "\RawData\ZM\" + $binary_file.Name
128 }
129
130 Write-Host "Files to copy:"
131 $files_to_copy
132 Write-Host ""
133
134 # loop through each file to copy
135 foreach ($file in $files_to_copy) {
136 $this_file_source = $this_participant_source + $file
137 $this_file_target = $this_participant_target + $file
138
139 # continue if file doesn't exist
140 if (!(Test-Path -Path $this_file_source)) {
141 continue
142 }
143
144 # create target directories if they don't exist
145 $this_file_target_dir = Split-Path -Path $this_file_target -Parent
146 if (!(Test-Path -Path $this_file_target_dir)) {
147 try {
148 New-Item -Path $this_file_target_dir -ItemType Directory > $null
149 }
150 catch {
151 Write-Host "Error creating directory: $this_file_target_dir, exiting script."
152 Read-Host "Press Enter to exit..."
153 exit
154 }
155 }
156
157 # continue if file already exists
158 if (Test-Path -Path $this_file_target) {
159 Write-Host "File already exists: $this_file_target"
160 continue
161 }
162
163 # copy file
164 try {
165 Copy-Item -Path $this_file_source -Destination $this_file_target > $null
166 Write-Host "Copied $this_file_source to $this_file_target"
167 }
168 catch {
169 Write-Host "Error copying file: $this_file_source to $this_file_target"
170 }
171 }
172
173 }
174}
175
176# Inform user that the script has finished
177Write-Host @"
178Script finished. Press Enter to exit...
179"@ -ForegroundColor Green
180Read-Host