mercredi 8 février 2017

Renaming a Folder and create a new folder in PowerShell

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:

  1. Rename my latest folder as _MM-dd-yyyy
  2. 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

Let's block ads! (Why?)



Renaming a Folder and create a new folder in PowerShell

Aucun commentaire:

Enregistrer un commentaire