Create Batch File using ROBOCOPY to move sub-folders and files

Asked By 230 points N/A Posted on -
qa-featured

Can someone help me create a DOS Batch file to move subfolders and files inside using robocopy "Robust File Copy".

The scenario goes this way:

I have a folder in c:rootfolderaa1bb2subfolder, now I want to move the bb2 folders including the subfolder to a new location. The location would be d:destionationfolderaa1.

However there are some folder inside the aa1 that are not to be included in the move and the bb2 folder name should not be constant.

The name should be updated everyday meaning that every day the bb2 folder should have a different name from the other day.

Is this possible?

Please provide me the batch script for this.

 

SHARE
Answered By 205 points N/A #108082

Create Batch File using ROBOCOPY to move sub-folders and files

qa-featured

ROBOCOPY – Robust File Copy

ROBOCOPY or Robust File Copy is available in Windows 7 operating system but not in Windows XP. ROBOCOPY is an alternative tool to copy or move files from any location. ROBOCOPY is a text base utility tool as an alternative external command for the internal command move and copy in DOS environment or command line interpreter (CLI).

This is also a powerful tool for backing-up files in the command line interpreter environment. This is new to windows operating system, and it is not yet openly introduce to all windows users.

Batch File programming or scripting is one of the oldest ways of scripting in DOS (Disk Operating System) environment or the Command Line Interpreter environment or the cmd.exe. It uses commands from DOS environment composed of internal and external commands. Internal commands are those commands which are already defined in our Command Line Interpreter.

CMD.EXE or COMMAND.COM has already stored it into the memory so that once the command was called; the command line interpreter will automatically execute it without any applications installed to that command. Some of the external commands are: dir, cls, echo, set, del, copy, cd, md and may more.

These are also the commands used in the batch file. The batch file script was created with a text editor or you may also create it with the copy console command or the COPY CON in the command line interpreter. Batch file programming or script is saved with the file name extension “. bat” meaning a batch file.

Here is a BATCH FILE sample to move a folder including files and subfolders inside the source to the destination folder (you may copy this code and paste it into your notepad and better to save it on your drive C and name it as ROBOMOV.BAT):

@echo off
ECHO ===========================
ECHO ROBOCOPY – Robust File Copy
ECHO A BATCH FILE FOR ROBOCOPY
ECHO
ECHO MOVE FUNCTION
ECHO
ECHO CREATED BY ROBERTO QUINTANA
ECHO EMAIL: ******@YAHOO.COM
ECHO CREATED FOR ALEXANDRIA
ECHO ===========================
ECHO.

SET PARAM1=P1_%1
SET PARAM2=P2_%2

IF %PARAM1% == P1_ GOTO SYNTAX
IF %PARAM2% == P2_ GOTO SYNTAX

REM BEGIN ROBOCOPY
REM Robocopy command below will move
REM the source folder to the destination folder
REM including all files and folders inside the
REM source folder

ECHO SOURCE: %1
ECHO DESTINATION: %2
ECHO.
ECHO Press CTRL+BREAK to abort batch file job.
pause

ROBOCOPY %1 %2 /S /MOVE

GOTO END

:SYNTAX
ECHO SYNTAX:
ECHO    ROBOMOV [SOURCE] [DESTINATION]
ECHO.
ECHO SAMPLE COMMAND:
ECHO    ROBOMOV C:ROOTFOLDERAA1BB2 D:DESTIONATIONFOLDERAA1BB2
ECHO.        
ECHO NOTE:
ECHO    BB2 WILL BE REMOVED FROM FC:ROOTFOLDERAA1 FOLDER
ECHO    IF YOU HAVE EXISTING D:DESTIONATIONFOLDERAA1 FOLDER AND
ECHO    BB2 IS NOT PRESENT ROBOCOPY WILL CREATE THE FOLDER BB2 WHICH
ECHO    IS THE FOLDER FROM YOUR SOURCE SO THAT ALL FILES AND SUBFOLDERS
ECHO    FROM THE SOURCE STILL REMAIN ON ITS FOLDER CONTAINER ON THE NEW
ECHO    LOCATION.

:END
SET PARAM1=
SET PARAM2=
ECHO.

To use this batch file, you must follow the instruction so that you may proceed with moving your file.

If you have some questions regarding the batch file or any modification you want.

Just contact the author stated in the comments.

Hope that this batch file will satisfy your need.

Related Questions