This is a small script I use to copy file quickly from source to destination. This script should work under Windows XP, 2000, 2003, 98/95 etc.
Syntax
Script accept two command line argument as follows:
mycopy.bat {source} {destination}
Where,
mycopy.bat - This script copies files and directories, including subdirectories using Windows xcopy program. You must pass following two arguments/parameters
source – Use to specify the location and names of the file/directory you want to copy.
destination - Use to specify the destination of the files you want to copy.
How do I use this script?
For example copy all *.doc file from C:\DATA to \\SERVER\BACKUP directory, you need to execute script as follows:
Cd c:\data
mycopy.bat *.doc \\SERVER\BACKUP
OR copy all files from c:\data to z:\
mycopy.bat c:\data\** z:\
mycopy.bat source code
@rem BATCH FILE
@echo off
if "%1" == "" goto error1
if "%2" == "" goto error2
@rem * Copy from source to destination including subdirs and hidden
@rem * File
xcopy "%1" "%2" /S /E /H
goto endofprogram
:error1
echo You must provide source
echo Syntax:
echo %0 source destination
goto endofprogram
:error2
echo You must provide destination
echo Syntax:
echo %0 source destination
goto endofprogram
:endofprogram
Where,
- Line # 03 and 04 make sure we pass the command line argument.
- Line # 08 - If both command line arguments (source and destination) are provided it will copy files using XCOPY program.
{ 16 comments… read them below or add one }
Can you tell me the windows script that shows how to tranfer files from one server to the other. I want to schedule a script that picks up all files and folders every 15 mins from one server and puts on to other server.. it would be very helpful if you provide me that.. thank you
I am trying to use the script above and I cannot understand where the destination and source network paths go. I will please appreciate if you could reply to my email as soon as possible.
Ex: if I want to copy files from “\\servername1\c:\Books” to “\\servername1\c:\Books” how I do that?
Roberto
i will be glad if i know how to used it
hi,
I jst wanted to copy all files from local folder d:\test\ to my network drive(server). i need a simple script to do that. then i can use scheduler to run it. need help
thanks
Hi vivek,
thanks for the script, i’m using it
only i’d like it to overwrite files without asking, what should i add to the script?
thx
gibit
use the /-Y switch.
or check type xcopy /? for other options
Hello…. can i have your inputs on this…
I like to copy some .tib files from one server to another. both are in the same network but one is joined to the domain. how to can i include the authentication in the script? e.g. copy all .tib files from drive of Server1 (workgroup) to another drive of server2 (joined to the domain)
Thanks
Thanks for the script. It works great.
Is there any revision for this script so that it will copy only the files that are created and modified within a specified date and time range.
Thanks
I’m looking for a script which will allow me to plug my flash drive into my laptop and automatically/ instantly copy files from different locations on my laptop into seperate folders on the flash drive.
Hi,
I m looking for a dos script to copy all the files from source to dest based on date range. I’m using windows server 2003.
Does not work if copying files with too long names or copying more than 37 thousand files.
How do I copy everything including the subdirectories? I can’t seems to do it with xcopy
Sorry, just found out my error. Thanks
where do i save the script in order to use it?
I want to copy files but keep a second copy of it using a a
batch without oveririting