Vote count: 0
My folder structure: C:\example\latest. I want to check if the subfolder latest already exists or not. If it does, I want to rename it as latest_MMddyyyy and then create a new folder called latest. If it does not have latest already, then simple create the folder.
This is what I have:
param (
$localPath = "c:\example\latest\"
)
#Creating a new directory if does not exist
$newpath = $localPath+"_"+((Get-Date).AddDays(-1).ToString('MM-dd-yyyy'))
If (test-path $localPath){
Rename-Item -path $localpath -newName $newpath
}
New-Item -ItemType -type Directory -Force -Path $localPath
It is doing two things:
- Rename my latest folder as _MM-dd-yyyy
- Throw an error: Missing an argument for parameter 'ItemType'. Specify a parameter of type 'System.String' and try again.
what am I doing wrong?
asked 27 secs ago
Renaming a Folder and create a new folder in PowerShell
Aucun commentaire:
Enregistrer un commentaire