locked
script that copy files based on extensions and prevent other extension RRS feed

  • Question

  • Hello I need a script that copies all files from a source to a destination but that pevents Jpeg, Mpeg, mp3, mp4, etc.... to be copied...

    Any idea?

     

    Thank you for your help...

    Thursday, July 28, 2011 9:56 PM

Answers

  • using Powershell:

    $excluded = "*.jpg","*.mpg","*.mp3","*.mp4"

    get-childitem <target directory> -exclude $excluded | foreach {copy-item $_.fullname -destination <target directory>}

    You can also put all the exclusions inline in the get-childitem cmdlet, but if there's that many of them it's probably easier to keep them in a separate array.


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    • Proposed as answer by Paul Frankovich Friday, July 29, 2011 1:43 PM
    • Marked as answer by IamMred Wednesday, August 17, 2011 4:13 AM
    Thursday, July 28, 2011 10:10 PM

All replies

  • Hi,

    Have you tried Robocopy? It has some exclusion options.

    Bill

    Thursday, July 28, 2011 10:02 PM
  • using Powershell:

    $excluded = "*.jpg","*.mpg","*.mp3","*.mp4"

    get-childitem <target directory> -exclude $excluded | foreach {copy-item $_.fullname -destination <target directory>}

    You can also put all the exclusions inline in the get-childitem cmdlet, but if there's that many of them it's probably easier to keep them in a separate array.


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    • Proposed as answer by Paul Frankovich Friday, July 29, 2011 1:43 PM
    • Marked as answer by IamMred Wednesday, August 17, 2011 4:13 AM
    Thursday, July 28, 2011 10:10 PM
  • mj, that's really cool.  Thanks, I didn't know about the -exclude parameter.  I am liking PS more and more.
    If you found this post helpful, please give it a "Helpful" vote. If it answered your question, remember to mark it as an "Answer".
    Friday, July 29, 2011 5:43 AM
  • Thank you!

    Can i create a powershell script and run it as a login script as a group policy?

    Friday, July 29, 2011 8:27 PM
  • Yes I can. I just checked on google and it's doable.  This is going to help me very much. Thanks again.
    Friday, July 29, 2011 8:28 PM