Copy each folder from 2020 named (NAME) to its mirror location in 2021

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
molosev
Posts: 2
Joined: 22 Jan 2021 03:23

Copy each folder from 2020 named (NAME) to its mirror location in 2021

#1 Post by molosev » 22 Jan 2021 04:00

Hello,

Let me explain what I am trying to do:
I want to copy each folder called "Reference_asset_folder" that is present in folder "2020" to its mirror location in folder "2021". (the folder 2021 already exists before the script is executed)

---------------------------------------------------------------------
Original tree structure:

2020
|_Address 1
---|_Reference_asset_folder
------|_Content_file
---|_Project 01
---|_Project 02
|_Address 2
---|_Reference_asset_folder
------|_Content_file
---|_Project 01
---|_Project 02
|_Address 3
---|_Project 01
---|_Project 02


Status of the 2021 folder after execution of the script:

2021
|_Address 1
---|_Reference_asset_folder
------|_Content_file
|_Address 2
---|_Reference_asset_folder
------|_Content_file

Note that nothing has been copied for Address 3 because it does not include a "Reference_asset_folder" folder in 2020.

---------------------------------------------------------------------
Does it seem possible to do this using a batch?
Could you provide me with some first steps so that I can try to develop this script?

Thank you very much in advance !

aGerman
Expert
Posts: 4080
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Copy each folder from 2020 named (NAME) to its mirror location in 2021

#2 Post by aGerman » 22 Jan 2021 11:50

Give that a go.

Code: Select all

@echo off
for /d %%i in ("2020\*") do (
  if exist "%%i\Reference_asset_folder\" (
    robocopy "%%i\Reference_asset_folder" "2021\%%~nxi\Reference_asset_folder" /s /e
  )
)
Steffen

molosev
Posts: 2
Joined: 22 Jan 2021 03:23

Re: Copy each folder from 2020 named (NAME) to its mirror location in 2021

#3 Post by molosev » 25 Jan 2021 05:58

Wow that's powerful !

I still have to adapt the code so that it also runs through the subfolders.

Have a great day Steffen !

Chris

Post Reply