none
Copying files to another folder, with Powershell RRS feed

  • Question

  • I have stored file paths which match particular text which I am looking for, in a variable. Now, what I want to do is copy those files, which match content I'm looking for, and put them into a new folder.

    I have written the following simple scripts, neither of which work:

    (I)

    Copy-Item -path $match in $filepaths -Destination C:\newfolder -Recurse

    (II) 

    foreach($match in $filepaths)
    {
     Copy-Item -path $match -Destination C:\newfolder
    }

    Any ideas as to how to make them work?


    Sunday, June 21, 2015 12:55 PM

All replies

  • I'd suggest this would be better asked over on the scripting forum https://social.technet.microsoft.com/Forums/en-US/home?forum=ITCG than here.

    Can you also confirm what's happening when you try those versions, eg what error are you getting from PowerShell? It would also be useful to see a sample of the content in $filepaths since that may indicate where within the script your issue is.

    Sunday, June 21, 2015 1:26 PM
  • Thanks for suggestion - I'll  transfer the question now.
    Sunday, June 21, 2015 1:51 PM