Created
June 10, 2023 10:39
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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