-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMove-LabFilesRoot.ps1
63 lines (54 loc) · 1.73 KB
/
Move-LabFilesRoot.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
<#
.Synopsis
Copy files from subdirectories to root directory.
.DESCRIPTION
After downloading your lab files, it will move the files from the modules folder to the root directory file structure.
All lab files have unique names.
Start:
Course files
├── Mod1
│ ├── coursefile1.pdf
│ ├── coursefile2.pdf
├── Mod2
│ ├── coursefile3.pdf
├── Mod3
│ ├── coursefile4.pdf
└──
End:
Course files
├── coursefile1.pdf
├── coursefile2.pdf
├── coursefile3.pdf
└── coursefile4.pdf
.PARAMETER LabFilesPath
The valid root path of the location of your Course Files.
.EXAMPLE
C:\PS>Move-LabFilesRoot -Path C:\CourseFiles
#>
function Move-LabFilesRoot {
[CmdletBinding()]
param (
# LabFilesPath The root folder of the Course Files.
[Parameter()]
[ValidateScript( { Test-Path $PSItem -PathType Container } )]
[string]
$LabFilesPath
)
if ($LabFilesPath -eq $env:SystemDrive) {
throw "Do not run this on $($env:SystemDrive)"
}
$allFiles = Get-ChildItem -Path $LabFilesPath -Recurse -File
foreach ($file in $allFiles) {
Move-Item -Path $file.Fullname -Destination $LabFilesPath -Force
}
# Not checking for hidden items
$allDirectories = Get-ChildItem -Path $LabFilesPath -Recurse -Directory
foreach ($directory in $allDirectories) {
if ($directory.GetFiles().Count -eq 0) {
Remove-Item -Path $directory.Fullname -Force
}
else {
Write-Warning -Message "Did not delete directory: $($directory.Name). Contents may still exist in directory."
}
}
}