Page 1 of 1

Move multiple subdirectories all with same name

Posted: 10 Jan 2022 07:49
by RickB
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

Re: Move multiple subdirectories all with same name

Posted: 10 Jan 2022 11:52
by aGerman
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

Re: Move multiple subdirectories all with same name

Posted: 11 Jan 2022 23:17
by Jedininja

Code: Select all

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

Re: Move multiple subdirectories all with same name

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

Steffen

Re: Move multiple subdirectories all with same name

Posted: 13 Jan 2022 21:34
by Jedininja
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

Re: Move multiple subdirectories all with same name

Posted: 14 Jan 2022 11:27
by aGerman
What is "foldername" for in your snippet? Again, read the initial post. The folders to be copied have the same name.

Steffen