Move multiple subdirectories all with same name

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
RickB
Posts: 1
Joined: 10 Jan 2022 07:43

Move multiple subdirectories all with same name

#1 Post by RickB » 10 Jan 2022 07:49

Hello,

I have a large number of folders, each of which has a subfolder for archived content. The subfolders in each folder all have the same name, e.g. "Archives." In order to conserve hard drive space, I want to move all of the Archives subfolders to a different drive, keeping the full directory tree structure intact in the process (in order to identify each Archives subfolder, and avoid duplicate folder name issues).

Can anyone suggest a batch file solution to accomplish this?

Thank you,

RickB

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

Re: Move multiple subdirectories all with same name

#2 Post by aGerman » 10 Jan 2022 11:52

Not sure I understood your request correctly. So, I guess you want to create the parent folder of your "Archives" too, but only copy the "Archives".

Code: Select all

@echo off &setlocal
set "src=C:\somewhere"
set "dst=D:\somewhere else"
set "find=Archive"

for /f "delims=" %%i in ('dir /ad /b /s "%src%\%find%"') do (
  for %%j in ("%%~i\..") do (
    robocopy "%%~i" "%dst%\%%~nxj\%%~nxi" /e /r:0 /w:0
  )
)
pause
Steffen

Jedininja
Posts: 25
Joined: 11 Jan 2022 22:41
Location: CanafukpilesDa
Contact:

Re: Move multiple subdirectories all with same name

#3 Post by Jedininja » 11 Jan 2022 23:17

Code: Select all

xcopy /e /i /q /-y path/targetfile.xxx %destination/path%

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

Re: Move multiple subdirectories all with same name

#4 Post by aGerman » 13 Jan 2022 13:28

Beside of the fact that xcopy is rather deprecated, how does it solve the problem of having always the same folder name "Archive!?

Steffen

Jedininja
Posts: 25
Joined: 11 Jan 2022 22:41
Location: CanafukpilesDa
Contact:

Re: Move multiple subdirectories all with same name

#5 Post by Jedininja » 13 Jan 2022 21:34

aGerman wrote:
13 Jan 2022 13:28
Beside of the fact that xcopy is rather deprecated, how does it solve the problem of having always the same folder name "Archive!?

Steffen
md drive/path/foldername & xcopy /e /i /q /-y path/targetfile.xxx drive/path/foldername

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

Re: Move multiple subdirectories all with same name

#6 Post by aGerman » 14 Jan 2022 11:27

What is "foldername" for in your snippet? Again, read the initial post. The folders to be copied have the same name.

Steffen

Post Reply