-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-folder.ps1
61 lines (49 loc) · 1.5 KB
/
create-folder.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
function LogDebug($message) {
Write-Host -ForegroundColor DarkGray $message
}
function LogInformation($message) {
Write-Host -ForegroundColor Cyan $message
}
function LogSuccess($message) {
Write-Host -ForegroundColor Green $message
}
function LogWarning($message) {
Write-Host -ForegroundColor Yellow $message
}
function LogError($message) {
Write-Host -ForegroundColor Red $message
}
function ExitFromScript($message,$line,$details) {
$message = $_.Exception.Message
$line = $_.InvocationInfo.ScriptLineNumber
$details = $_.CategoryInfo
LogError "An Error has occurred: $message
`nline: $line
`nError Details: $details"
LogWarning "Stopping the script.`n"
LogWarning "Press any key...`n"
$null = Read-Host
Exit
}
function CreateFolder ($FolderName) {
LogInformation "- Creating dir $FolderName ..."
LogDebug " Creating dir $FolderName ..."
if (-not (Test-Path -Path $FolderName -PathType Container)) {
New-Item -ItemType Directory -Path $FolderName
LogSuccess " Create dir $FolderName successfully!`n"
}
else {
LogWarning " directory $FolderName already exists.`n"
}
}
################# First usage #################
param(
[Parameter(Position = 0, mandatory)]
[string]$FolderName
)
CreateFolder $FolderName
################# second usage #################
$Dirs_Paths = @("path/folder1","path/folder2")
for($i = 0; $i -lt $Dirs_Paths.length; $i++){
CreateFolder($Dirs_Paths[$i])
}