-
Notifications
You must be signed in to change notification settings - Fork 17
/
mbcopy.bat
107 lines (73 loc) · 1.7 KB
/
mbcopy.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
@echo off
rem
rem MBCOPY.BAT
rem Author: Mike Boldin, Niagara College
rem
rem Description:
rem
rem MBCOPY.BAT copies any number of files or directories to
rem to a directory.
rem
rem The command uses the following syntax:
rem mbcopy dest src1 src2 ...
rem
rem Modification History:
rem 2000.09.15 Modified original MYCOPY.BAT for Lab #2
rem
rem
if "%1"=="" goto usage
if "%2"=="" goto usage
if not "%1"=="/?" goto start
:usage
rem
rem Show usage
rem
echo usage: %0 dest-dir src [...]
echo where: dest-dir is the destination directory
echo src is a file or directory to copy (multiple src
echo files or directories may be specified)
goto end
:start
setlocal
set todir=%1
rem
rem If the destination directory does not exist, create it
rem
if exist %todir%\nul goto getfile
echo Creating directory %todir%
md %todir%
if not errorlevel 1 goto getfile
echo Error creating directory %todir%
goto end
:getfile
shift
if "%1"=="" goto endok
rem
rem If the source file is a directory, it gets copied differently
rem from an ordinary file
rem
if exist %1\nul goto copydir1
copy %1 %todir% > nul
goto check
:copydir1
rem
rem If the source directory does not already exist in the
rem destination directory, create it so that XCOPY does not
rem prompt the user
rem
if exist %todir%\%1 goto copydir2
md %todir%\%1
if not errorlevel 1 goto copydir2
echo Error creating directory %todir%\%1
goto end
:copydir2
xcopy %1 %todir%\%1 /s /e > nul
:check
if not errorlevel 1 goto getfile
echo Error copying %1
goto end
goto getfile
:endok
echo All done
:end
endlocal