-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.ps1
135 lines (110 loc) · 5.05 KB
/
script.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
$CLDIR = ".\Cover letter"
$RDIR = ".\Resume"
$Dest = ".\Package"
$TDIR = ".\Transcript"
$Archive = "Archive"
<# Files that need to exist before usage #>
$Rtmp = "$($RDIR)\R-Template"
$CLtmp = "$($CLDIR)\CL-Template"
$LOG = ".\log"
$Userfile = ".\username"
$CLsig = "CL"
$Rsig = "R"
# Checks if all the file paths are created, if not created it will initialize them
@($CLDIR, $RDIR, $Dest, $TDIR, "$($RDIR)\$($Archive)", "$($CLDIR)\$($Archive)") | ForEach-Object { if (!(Test-Path -Path $_)) {
try {
New-Item -ItemType "directory" -Path $_ | Out-Null
Write-Host "Created directory $_" -ForegroundColor green
}
catch {
Write-Host "Failed to create directory $_" -ForegroundColor red
}
} }
# Check if csv log file exists, create them if not
@("$Rtmp.docx", "$CLtmp.docx", "$LOG.csv", "$Userfile.txt") | ForEach-Object { if (!(Test-Path -Path $_)) {
try {
New-Item -ItemType "file" -Path $_ | Out-Null
Write-Host "Created file $_" -ForegroundColor green
}
catch {
Write-Host "Failed to create file $_" -ForegroundColor red
}
} }
:exitLabel while ($true) {
# User Input
$Company = (Read-Host "Enter the company name").TrimStart().TrimEnd().replace(' ', '_')
$Position = (Read-Host "Enter the position to apply").TrimStart().TrimEnd().replace(' ', '_')
$err = $false
# If username file is empty ask for username and write to file
if ([String]::IsNullOrWhiteSpace((Get-content "$Userfile.txt"))) {
$User = (Read-Host "Enter your name").TrimStart().TrimEnd().replace(' ', '_')
Add-Content -Path "$Userfile.txt" -Value $User
Set-ItemProperty -Path "$Userfile.txt" -Name IsReadOnly -Value $true
}
else {
$User = Get-Content -Path "$Userfile.txt" -TotalCount 1
}
$CLfilename = "$($CLDIR)\$($CLsig)-$($Position)-$($Company)"
$Rfilename = "$($RDIR)\$($Rsig)-$($Position)-$($Company)"
$CLNewfilename = "$($Dest)\$($User)-$($Position)-$($Company)-Coverletter"
$RNewfilename = "$($Dest)\$($User)-$($Position)-$($Company)-Resume"
$TNewfilename = "$($Dest)\$($User)-$($Position)-$($Company)-Transcript"
if ((Read-Host "`nCreate a new resume and coverletter from template? [Y] / [N]") -eq 'Y') {
Copy-Item -Path "$Rtmp.docx" -Destination "$Rfilename.docx"
ii "$Rfilename.docx" ; Write-Host "Created the initial resume file" -ForegroundColor green
Copy-Item -Path "$CLtmp.docx" -Destination "$CLfilename.docx"
ii "$CLfilename.docx" ; Write-Host "Created the initial coverletter file" -ForegroundColor green
Read-Host -Prompt "`nPress any key to continue once ready with the pdfs or CTRL+C to quit"
}
Remove-Item -path "$($Dest)/*" -Include *.pdf -Exclude *"$($Position)-$($Company)"*
# Copy Cover letter
try {
Get-ChildItem "$CLfilename.pdf" -ErrorAction stop | Copy-Item -Destination "$CLNewfilename.pdf" ; ii "$CLNewfilename.pdf" ; Write-Host "Copied Coverletter file to destination" -ForegroundColor green
Get-ChildItem $CLfilename* -ErrorAction stop | Move-Item -Destination "$($CLDIR)\$($Archive)"
}
catch {
Write-Host "Failed to copy $($CLfilename)" -ForegroundColor red
$err = $true
}
# Copy Resume
try {
Get-ChildItem "$Rfilename.pdf" -ErrorAction stop | Copy-Item -Destination "$RNewfilename.pdf" ; ii "$RNewfilename.pdf" ; Write-Host "Copied Resume file to destination" -ForegroundColor green
Get-ChildItem $Rfilename* | Move-Item -Destination "$($RDIR)\$($Archive)"
}
catch {
Write-Host "Failed to copy $($Rfilename)" -ForegroundColor red
$err = $true
}
# Copy Current Transcript
try {
Get-ChildItem "$($TDIR)\Current_Transcript.pdf" -ErrorAction stop | Copy-Item -Destination "$TNewfilename.pdf" ; ii "$TNewfilename.pdf" ; Write-Host "Copied Transcript file to destination" -ForegroundColor green
}
catch {
Write-Host "Failed to copy Current_Transcript.pdf" -ForegroundColor red
$err = $true
}
$date = Get-Date -Format "MM/dd/yyyy"
$time = Get-Date -Format "HH:mm K"
# If log file is empty create header
if ([String]::IsNullOrWhiteSpace((Get-content "$LOG.csv")), !$err) {
"{0}, {1}, {2}, {3}" -f "Company", "Position", "Submision Date mm/dd/yyyy", "Time" | add-content "$LOG.csv"
}
"{0}, {1}, {2}, {3}" -f $Company, $Position, $date, $time | add-content "$LOG.csv"
while ($true) {
$in = Read-Host "`nSome files failed be copy, Try again? [Y] / [N]"
if ($err) { if ($in -eq 'Y') { break skipuserinput }
elseif ($in -eq 'N') {
$in = Read-Host "`nStart a new application [Y] / [N]"
if ($in -eq 'N') {
break exitLabel
}
elseif ($in -eq "Y") {
break
}
}
}
}
}
# Print lenght of the csv file excluding header
Write-Host "`nNumber of postion applied to: $(((Get-Content "$LOG.csv").Length) - 1)"
Read-Host -Prompt "Press ENTER to exit program"