Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com
In our PowerShell scripts for different folder it's required to delete if exist and create empty folder. To avoid to repeat folder name in three commands I've created a function

function DeleteIfExistsAndCreateEmptyFolder($dir )
{
      if ( Test-Path $dir ) {
            Remove-Item -Recurse -Force $dir
    }
    New-Item -ItemType Directory -Force -Path $dir
}

I've also used this function in  answer for SuperUser question How can I copy a directory, overwriting its contents if it exists using Powershell?
Posted on Wednesday, January 27, 2016 7:58 PM Batch files/PowerShell | Back to top


Comments on this post: PowerShell function to delete if exist and create empty folder

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net