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.