none
Move specific files retaining folder structure RRS feed

  • Question

  •     Hi,

    I'm trying to build a script using batch or powershell. But I was unable to build or find a script that do what I need.

    Can you help me, please.

    I need a script that move all the images that are in C:\My_files and his subfolders to X:\My_result

    In others words, I have something like this :

    C:\My_files\1.jpg
    C:\My_files\2.bmp
    C:\My_files\Subfolder1\best.jpg
    C:\My_files\Subfolder1\AnotherSubFolder\picture.jpg
    C:\My_files\Subfolder1\AnotherSubFolder\text.txt
    C:\My_files\Subfolder1\AnotherSubFolderX\something.xls

    And I need this :

    X:\My_result\1.jpg
    X:\My_results\2.bmp
    X:\My_result\Subfolder1\best.jpg
    X:\My_result\Subfolder1\AnotherSubFolder\picture.jpg
    Thanks for your help.


    • Edited by villegente Wednesday, April 11, 2018 6:00 AM
    Wednesday, April 11, 2018 5:59 AM

Answers

  • For this task you don't need a script at all. You can use xcopy or robocopy to do that.

    Open a CMD and type xcopy /?  or robocopy /? to learn about their parameters.


    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Wednesday, April 11, 2018 6:27 AM

All replies

  • Have a look at Copy-Item, it can do exactly what you're asking for.
    Wednesday, April 11, 2018 6:20 AM
  • For this task you don't need a script at all. You can use xcopy or robocopy to do that.

    Open a CMD and type xcopy /?  or robocopy /? to learn about their parameters.


    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Wednesday, April 11, 2018 6:27 AM
  • Thanks for your answers.

    I have already try CopyItem and robocopy but without success. I will have another try today and probably send a copy of my script.

    Wednesday, April 11, 2018 7:12 PM
  • As noted already, you don't need a script.

    Just type the robocopy command followed by each folder name and /E on the command line, then press Enter.

    This is not an end-user support forum but a place to ask scripting questions.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 11, 2018 7:16 PM
    Moderator