locked
Issue with powershell script to copy folders and files RRS feed

  • Question

  • Just trying to copy all folders and subfolders and files inside that by adding exclude filter in powershell script.

    All the folders are getting copied but its not copying the subfolders and files .

    Below is the script am using Its copying only the root folders not subfolders and files.Please could you help me out here..

    $sourcePath - Project root folder

    $destPath - Destination folder

    $exclude = @('Web.Debug.config','Web.Release.config','Controllers','Models','obj','*.csproj','*.vspscc','*.cs','*.html')
    Get-ChildItem $sourcePath -Exclude $exclude | Where-Object { $_.Length -eq $null } | % {

    Copy-WithFilter $_.FullName (Join-Path -Path $destPath -ChildPath $_.Name)


     if (!(Test-Path $destPath))

    {

    New-Item -Path $destPath -ItemType Directory | Out-Null

    }
    Get-ChildItem $sourcePath -Exclude $exclude | Where-Object { $_.Length -ne $null } | Copy-Item -Destination $destPath

    Copy-WithFilter $sourcePath $destPath 

    • Moved by Albert_Zhang Thursday, June 23, 2016 1:33 AM From MSBuild Forum
    Tuesday, June 21, 2016 2:46 PM

Answers

  • Hi Amit,

    >>All the folders are getting copied but its not copying the subfolders and files .

    Please add a -recurse parameter.

    Copy-Item -Path $sourcepath -Recurse -Destination $destpath -Force
    Best regards

    Andy_Pan

    • Proposed as answer by Hello_2018 Friday, July 1, 2016 3:47 AM
    • Marked as answer by Hello_2018 Monday, July 4, 2016 8:33 AM
    Friday, June 24, 2016 3:42 AM

All replies

  • Hi Amit_kl,

    This forum is about the usage of MSBuild tool, as I searched, I found the following log that provides a demo to recursively copy folder and you could have a look.

    http://techblog.dorogin.com/2013/01/powershell-recursively-copy-folder-structure.html

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Best Regards,

    Albert Zhang

    Wednesday, June 22, 2016 10:19 AM
  • Hi Amit,

    >>All the folders are getting copied but its not copying the subfolders and files .

    Please add a -recurse parameter.

    Copy-Item -Path $sourcepath -Recurse -Destination $destpath -Force
    Best regards

    Andy_Pan

    • Proposed as answer by Hello_2018 Friday, July 1, 2016 3:47 AM
    • Marked as answer by Hello_2018 Monday, July 4, 2016 8:33 AM
    Friday, June 24, 2016 3:42 AM