-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create-Folder.ps1
42 lines (32 loc) · 1.1 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
# Create Folder in Directory
## Use: ./Create-Folder.ps1 -folderName "ayoub ali"
param (
[Parameter(Mandatory=$true)]
[string]$folderName
)
# Function to capitalize the first letter of each word
function Capitalize-FirstLetter {
param (
[Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
[string]$string
)
$cultureInfo = (Get-Culture).TextInfo
$cultureInfo.ToTitleCase($string.ToLower())
}
# Split the folder name into individual words
$words = $folderName -split ' '
# Remove spaces from each word and capitalize the first letter
$capitalizedWords = foreach ($word in $words) {
$word = $word -replace '\s', ''
Capitalize-FirstLetter -string $word
}
# Join the capitalized words back into a single string
$folderName = $capitalizedWords -join ''
# Check if the folder already exists
if (Test-Path $folderName) {
Write-Host "Folder '$folderName' already exists."
exit 1
}
# Create the folder
New-Item -ItemType Directory -Path $folderName -Force | Out-Null
Write-Host "Folder '$folderName' created successfully."