Skip to content

Instantly share code, notes, and snippets.

@ayoubzulfiqar
Created June 10, 2023 10:39
Show Gist options
  • Select an option

  • Save ayoubzulfiqar/0252f52d0ea7132f95d29feaecd8566b to your computer and use it in GitHub Desktop.

Select an option

Save ayoubzulfiqar/0252f52d0ea7132f95d29feaecd8566b to your computer and use it in GitHub Desktop.
This Script Create a Folder and remove all the Spaces between the Words and turn all prefix letter of Each Word
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."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment