none
how to avoid copying specfic file using powershell RRS feed

  • Question

  • Hi i would like to copy content from a folder but there is 1 specific file called Web.config which i do not want to copy.

    i am using the following script but no luck

    $unzipAdmin = 'c:\Temp\unzipAdmin'

    $copyAdmin = $unzipAdmin + "/Content/*" 

    get-childitem "C:\deployments\website" -recurse | % {
    if($_.Name -ne 'Web.config')
    {

    Copy-Item  -Path $copyAdmin -Destination 'C:\Projects\Admin' -Recurse -force
    }

    }

    all files and folders are inside content, so i would like to copy every thing except Web.config and 1 folder which is called Deploy

    Wednesday, September 24, 2014 4:00 PM

Answers

  • Copy-Item  -Path $copyAdmin -Destination 'C:\Projects\Admin' -Exclude *web.config* -Recurse -force

    Always start with help until you learn the base CmdLets.  It will save you a lot of time.

    HELP Copy-Item -Full



    ¯\_(ツ)_/¯

    Wednesday, September 24, 2014 4:18 PM

All replies

  • Copy-Item  -Path $copyAdmin -Destination 'C:\Projects\Admin' -Exclude *web.config* -Recurse -force

    Always start with help until you learn the base CmdLets.  It will save you a lot of time.

    HELP Copy-Item -Full



    ¯\_(ツ)_/¯

    Wednesday, September 24, 2014 4:18 PM
  • it worked just perfect, but other part of my question, is it possible to include "Deploy" as well with in 1 copy command. when i use the same copy command for folder it doesnt work, infact than the first copy doesnt work
    Wednesday, September 24, 2014 4:28 PM
  • as soon as i have another copy command so that i can exclude folder, the 1st copy command stops working i mean it includes Web.config file. If i use 1 copy than its fine, but i need to exclude the folder aswell. its called "Deploy"
    Wednesday, September 24, 2014 4:32 PM
  • I have no idea what you are trying to say.  The Copy-Item  Will copy everything and exclude items exluded.

    Read the help carefull please.

    You can add multiple excludes in the same command.


    ¯\_(ツ)_/¯

    Wednesday, September 24, 2014 5:31 PM