Batch file to copy files from one folder to another folder


I have a storage folder on a network in which all users will store their active data on a server. Now that server is going to be replaced by a new one due to place problem so I need to copy sub folders files from the old server storage folder to new server storage folder. I have below ex:

from \Oldeserver\storage\data & files to \New server\storage\data & files.

7/28/2014 7:38:21 PM

My favorite one to backup data is:

ROBOCOPY "C:\folder" "C:\new_folder" /mir

/mir is for mirror. You can also use /mov to move files. It reproduce the exact same folder. It can delete/overwrite files as needed. Works great for me. It's way faster than xcopy / copy. It's built in Windows as well.



Just to be clear, when you use xcopy /s c:\source d:\target, put "" around the c:\source and d:\target,otherwise you get error.

ie if there are spaces in the path ie if you have:

"C:\Some Folder\*.txt"

but not required if you have:


You may want to take a look at XCopy or RoboCopy which are pretty comprehensive solutions for nearly all file copy operations on Windows.


To bypass the 'specify a file name or directory name on the target (F = file, D = directory)?' prompt with xcopy, you can do the following...

echo f | xcopy /f /y srcfile destfile

or for those of us just copying large substructures/folders:

use /i which specifies destination must be a directory if copying more than one file


if you want to copy file not using absolute path, relative path in other words:

don't forget to write backslash in the path AND NOT slash

example :

    copy children-folder\file.something .\other-children-folder

PS: absolute path can be retrieved using these wildcards called "batch parameters"

    @echo off
    echo %%~dp0 is "%~dp0"
    echo %%0 is "%0"
    echo %%~dpnx0 is "%~dpnx0"
    echo %%~f1 is "%~f1"
    echo %%~dp0%%~1 is "%~dp0%~1"

check documentation here about copy :

and also here for batch parameters documentation: