Last active
June 10, 2023 10:44
-
-
Save ayoubzulfiqar/46ffaea0935dd89d98170abf8e50c7f9 to your computer and use it in GitHub Desktop.
This Script create a new file and turn all the all the words into LowerCase and replace the space with underscore(_)
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]$FileName | |
| ) | |
| # Convert the file name to lowercase | |
| $NewFileName = $FileName.ToLower() | |
| # Replace spaces with underscores | |
| $NewFileName = $NewFileName -replace '\s', '_' | |
| # Check if the file already exists | |
| if (Test-Path -Path $NewFileName -PathType Leaf) { | |
| Write-Output "File '$NewFileName' already exists." | |
| # You can choose to skip the creation of the new file or rename the existing file here. | |
| } | |
| else { | |
| # Create a new file with the modified name | |
| $NewFile = New-Item -ItemType File -Path $NewFileName -ErrorAction Stop | |
| # Output the new file name | |
| Write-Output "New file created: $NewFileName" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment