Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9230919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:56:17+00:00 2026-06-18T05:56:17+00:00

I need to copy only certain parts of a folder using Powershell, specifically this

  • 0

I need to copy only certain parts of a folder using Powershell, specifically this list:

$files = @("MyProgram.exe",
           "MyProgram.exe.config",
           "MyProgram.pdb",
           ".\XmlConfig\*.xml")

In human readable form: 3 specific MyProgram.* files under root of target folder and all XML files under XmlConfig folder which itself is under root of source path (..\bin\Release\ in my case). XmlConfig folder must be created in destination, if it does not exist.

What I have tried:

(1) I tried the following, but it did not work, i.e. no folder or files were created at the destination path:

Copy-Item -Recurse -Path "..\bin\Release\" -Destination ".\Test\" -Include $files

(2) When -Include is removed, whole folder structure is successfully created, including subfolders and files:

Copy-Item -Recurse -Path "..\bin\Release\" -Destination ".\Test\"

It must be something wrong with my understanding of how -Include filter works:

(3) I tested an assumption that -Include needs an array of wildcards, but this did not work either:

$files = @("*MyProgram.exe*",
           "*MyProgram.exe.config*",
           "*MyProgram.pdb*",
           "*.\XmlConfig\*.xml*")

Please advise on how to properly do Copy-Item in my case.

UPDATE (based on below answers):

I am looking for a generic implementation that takes an array of strings. It opens the possibility to put all necessary files/paths in one place, for easy editing, so that a non-Powershell knowledgeable person can understand and modify it as required. So in the end it would be single script to perform XCOPY deployments for any project, with input file being the only variable part. For above example, the input would look like this (saved as input.txt and passed as an argument to the main script):

MyProgram.exe
MyProgram.exe.config
MyProgram.pdb
.\XmlConfig\*.xml

I would prefer wildcards approach, since not many people know regex.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:56:19+00:00Added an answer on June 18, 2026 at 5:56 am

    i don’t know what is wrong with filter but you can still do

    $files | % { copy-item ..\bin\release\$_ -Destination .\test}
    

    if you want to preserve directoty structure you’ll have to weak this a little, like :

    $sourcedir="c:\temp\test"
    $f=@("existing.txt","hf.csv";"..\dir2\*.txt")
    $f |%{
         $source=ls (join-Path $sourcedir $_) |select -expand directoryname    
         if ("$source" -like "$sourcedir*"){
            $destination=$source.Substring($sourcedir.Length)+".\" 
         }
         else{
            $destination=$_
         }  
        copy-item $sourcedir\$_ -Destination $destination -WhatIf
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to copy read-only files in Perl. I tried using Perl::Copy function, but
I need a script to copy only the changed/modified and new files from my
I need to copy files and directories within a directory. Suppose there is only
I need to copy all *.exe files in some directory to other virtual drive
I need to copy several files to remote server. for database in `mysql -Bseshow
I need to copy two linked lists recursively and return a new list .
I need to copy files in one directory to another directory where the lastwritetime
I need to recursively copy a directory (C:\test in this case) to a remote
I only need to copy a file from a remote server to a local
Im trying to copy data only between two SQL server 2008 databases. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.