locked
how do I move folders containing certain number in their filenames from one location to another location using powershell? RRS feed

  • Question

  • Hello,

    I am trying to move FOLDERS (along with its file contents) in certain directory into another if these folders contain certain numbers in their filenames.

    For example, if I want to move all the folders containing "1515" in its name,

    how do I move only C:\p\a\t\h\test1515 from the directory containing:

    C:\p\a\t\h\test1515

    C:\p\a\t\h\1516test

    C:\p\a\t\h\t1e5s1t5

    ?

    What command line should I use?

    I am a total noob so if you could provide some explanation to the command used I would really appreciate it.

    Thanks in advance,

    Saturday, December 8, 2018 9:01 AM

All replies

  • use robocopy $source $target /MOVE

    Chris

    Saturday, December 8, 2018 10:08 AM
  • Try this:

    Get-ChildItem <parent-directory> -Recurse -Directory | Where {$_.PSChildName -like "*1515*"} | Move-Item -Destination <where-to-move>


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    • Proposed as answer by jrv Saturday, December 8, 2018 5:56 PM
    Saturday, December 8, 2018 3:32 PM
  • move-item C:\p\a\t\h\*1515* c:\wherever

    Saturday, December 8, 2018 6:11 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Tuesday, December 11, 2018 6:15 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Monday, December 24, 2018 5:46 AM