1

I have a function (.bat) to search and rename (or move) any folder with a specific name folder (call "data"), with all its contents intact, on a specific path (path:\ Is the specific route like c:\ or h:)

I need to simplify it and make it work.

call:test "TEST1"
call:test "TEST2"

:: funcion test
@echo off
pause
goto:eof
:test
 set test=%1
 CD /D path:\
 if exist "%test%" (goto make) else (goto end)
 :make
 MOVE /Y "%test%" data
 FOR /F %%x IN ("%test%") DO REN "%%x" data
 FOR /F "tokens=*" %%G IN ('DIR /B /AD /S "%test%"') DO MOVE /Y "%%G" data
 :end
 echo OK
 goto:eof

The TEST1 and TEST2 folders contain many files and subfolders. The problem is that i use three commands to do this work and not 100% works.

 MOVE /Y "%test%" data
 FOR /F %%x IN ("%test%") DO REN "%%x" data
 FOR /F "tokens=*" %%G IN ('DIR /B /AD /S "%test%"') DO MOVE /Y "%%G"

I need to rename the folders TEST1 and TEST2, wherever they are within the path (may be in the root or in subfolders. Both should be renamed (merged) as "data").

Example: The TEST1 and TEST2 folders have content (files and subfolders). The ".bat" search into the path to find TEST1 and when it finds renamed TEST1 with "data". Keep looking and find TEST2 and rename as "data" too without asking.

But, in the case of both folders (TEST1 and TEST2) are within the same location, both should be merged (one overrides the other). The important thing is to do it without asking.

But "MOVE /Y" does not overwrite folders (only files). I think the solution could be that instead of overwriting, rename the file or folder duplicate to avoid this failure command

Note: Previously i used Robocopy with "move" option...

SET MoveDirSource=path:\"%test%"
SET MoveDirDestination=path:\data
MKDIR "%MoveDirDestination%"
FOR %%i IN ("%MoveDirSource%\*") DO MOVE /Y "%%i" "%MoveDirDestination%\%%~nxi"
FOR /D %%i IN ("%MoveDirSource%\*") DO ROBOCOPY /MOVE /E /W:5 "%%i" "%MoveDirDestination%\%%~nxi"

But it is not viable, because robocopy, first, copy from source to destination and then removed at source. And if TEST1 or TEST2 folders have 2 or 6 GB of information, this process can take hours.

Thanks a lot

1
  • thanks @DavidPostill That's why I have published. To help me correct that. Remember that the TEST1 and TEST2 folder can be repeated within subfolders
    – BrianC
    Commented Oct 7, 2016 at 21:26

1 Answer 1

1

I would use

ROBOCOPY "%Test%" Data /MOVE /E

Robocopy is installed by default in windows and does all what you want in one pass.

1
  • thanks but robocopy is not viable. Read why in "Note:". Thanks anyway
    – BrianC
    Commented Oct 7, 2016 at 23:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .