Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

How to copy files based on list of array?

$
0
0

Hi Guys,

I need to copy files from sourceA to either destA or destB based on if the filename matches the array of string in an external file or not.

For example:

I have 3 files in SourceA:

CATisNice.txt
DogisPretty.txt
HorseisFast.txt

I have following list of strings in a text file, lets say listA.txt:

Nice
Pretty

Now I need script to check each file and see if its name matches  any string in the  listA.txt

If matches, copy the file to both destA and destB

If not copy only to destB

In the above example, I should see CATisNice.txt, DogisPretty.txt in destA and CATisNice.txt,DogisPretty.txt, HorseisFast.txt in destB

I know only very very basic of powershell and not sure how to loop through the array of value for each object.

Thank you very much for your time and help

Let me know if smething is no clear

 

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles