home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / c / clone1_1.zip / CLONE.BAT < prev    next >
DOS Batch File  |  1993-01-07  |  16KB  |  410 lines

  1. echo off
  2. if "%1"==".entry2" goto entry2
  3. if "%1"==".sub1" goto sub1
  4. if "%1"==".sub2" goto sub2
  5. if "%1"==".sub3" goto sub3
  6. if "%2"==".sub4" goto sub4
  7. if "%2"==".sub5" goto sub5
  8. if "%1"==".sub6" goto sub6
  9. if "%1"==".sub7" goto sub7
  10.  
  11. echo CLONE vs. 1.1 sends a complete drive, or a part of it (branch) serially to
  12. echo another machine into a specific subdirectory. (c) 1993, Jim Groeneveld, NL
  13. echo.
  14. rem Necessary auxiliary files: SUBST.*, FIND.* (DOS) and DISK.COM, ZIP.COM (vs. 1.51);
  15. if "%1"=="" goto help
  16. if "%1"=="?" goto help
  17. if "%1"=="/?" goto help
  18. if "%1"=="-?" goto help
  19. if "%1"=="/h" goto help
  20. if "%1"=="/H" goto help
  21. echo Wait.............processing arguments..................
  22. for %%a in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do if "%%a"==".s" goto repeat_1
  23. for %%a in (%1 %2 %3 %4 %5 %6 %7 %8 %9) do if "%%a"==".S" goto repeat_1
  24. goto chk_tmp
  25.  
  26. :repeat_1
  27. %0 .sub1 %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
  28. rem never pass here!
  29.  
  30. :entry2
  31. shift
  32. shift
  33. if "%1"=="" goto help
  34. goto no_filspec
  35.  
  36. :chk_tmp
  37. if not exist $dirlist.bat goto no_dirlist
  38.   echo *** Temporary file $DIRLIST.BAT already exists, cannot proceed;
  39.   echo     remove or rename $DIRLIST.BAT or specify '.s' option.
  40.   goto end
  41. :no_dirlist
  42. if not exist $ziplist.bat goto no_ziplist
  43.   echo *** Temporary file $ZIPLIST.BAT already exists, cannot proceed;
  44.   echo     remove or rename $ZIPLIST.BAT or specify '.s' option.
  45.   goto end
  46. :no_ziplist
  47. if not exist $fillist.bat goto no_fillist
  48.   echo *** Temporary file $FILLIST.BAT already exists, cannot proceed;
  49.   echo     remove or rename $FILLIST.BAT or specify '.s' option.
  50.   goto end
  51. :no_fillist
  52. if not exist $filspec.bat goto no_filspec
  53.   echo *** Temporary file $FILSPEC.BAT already exists, cannot proceed;
  54.   echo     remove or rename $FILSPEC.BAT or specify '.s' option.
  55.   goto end
  56.  
  57. :no_filspec
  58. if exist $dirlist.bat del $dirlist.bat
  59. if exist $dirlist.bat goto $dirlist
  60. if exist $ziplist.bat del $ziplist.bat
  61. if exist $ziplist.bat goto $ziplist
  62. if exist $fillist.bat del $fillist.bat
  63. if exist $fillist.bat goto $fillist
  64. if exist $filspec.bat del $filspec.bat
  65. if exist $filspec.bat goto $filspec
  66.  
  67. rem Search %2 for file specification: a. empty
  68. if "%2"=="" goto nofilespec
  69. rem b. Search %2 for starting '/', if so: parameter (see file UNDOCU'D.DOS)
  70. for %%b in (/%2) do if %%b==/ goto nofilespec
  71. rem c. Search %2 for starting '.', if so: parameter (see file UNDOCU'D.DOS)
  72. for %%b in (/%2) do if %%b==. goto nofilespec
  73.  
  74. :file_spec
  75. rem if "%1"=="\" goto error1         These subst path specifications appear to
  76. rem if "%1"=="." goto error1         work correctly, as does any relative path
  77. rem if "%1"==".." goto error1        specification, at least with DOS 3.3 .
  78. for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do if "%1"=="%%a" goto error1
  79. for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if "%1"=="%%a" goto error1
  80. for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do if "%1"=="%%a:" goto error1
  81. for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if "%1"=="%%a:" goto error1
  82. if "%1"=="z:\" goto error1
  83. if "%1"=="Z:\" goto error1
  84.  
  85. for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y) do if "%1"=="%%a:\" goto begin
  86. for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y) do if "%1"=="%%a:\" goto begin
  87. if exist %1 goto is_file
  88. if exist %1\*.* goto begin
  89.   ctty nul
  90.   rem>%1\$chkpath.nul
  91.   ctty con
  92.   if not exist %1\$chkpath.nul goto not_existing
  93.   del %1\$chkpath.nul
  94. :begin
  95. if exist Z:\*.* goto z_exists
  96.   ctty nul
  97.   rem>Z:\$chkpath.nul
  98.   ctty con
  99.   if not exist Z:\$chkpath.nul goto nosubstz
  100.     del Z:\$chkpath.nul
  101.  
  102. :z_exists
  103. echo --- Existing substitution or network assignment of drive Z: will be lost;
  104. echo     drive Z will be temporarily substituted as %1
  105. echo     Restore original substitution after termination of this program:
  106. subst|find "Z:"
  107. net use|find "Z:"
  108. echo (Ignore eventual "Bad command or file name" above...........)
  109.  
  110. :nosubstz
  111. rem If Z: is write protected its existence can not be checked. So to be
  112. rem sure Z: is being freed below from substitution or network assignment.
  113. subst z: /d >nul
  114. rem disconnect drive Z: from network, ignore eventual error message..........
  115. ctty nul
  116. net use z: /d >nul
  117. ctty con
  118.  
  119. rem check whether Z: now indeed does not exist
  120. if not exist Z:\*.* goto mount
  121.   ctty nul
  122.   rem>Z:\$chkpath.nul
  123.   ctty con
  124.   if not exist Z:\$chkpath.nul goto mount
  125.     del Z:\$chkpath.nul
  126.     echo *** Existing drive Z:\ could not be disconnected successfully.
  127.     echo     It still may be ASSIGNed or otherwise existing. Program abort!
  128.     goto beep
  129.  
  130. :mount
  131. rem substitute Z: to specified drive:\path to transfer
  132. subst z: %1 >nul
  133. rem and check whether substitution succeeded
  134. if exist Z:\*.* goto zz_exists
  135.   ctty nul
  136.   rem>Z:\$chkpath.nul
  137.   ctty con
  138.   if not exist Z:\$chkpath.nul goto no_z_nul
  139.     del Z:\$chkpath.nul
  140.  
  141. :zz_exists
  142. echo --- Cloning branch: %1, file specification: %2
  143. if not "%3"=="" echo     Additional option(s): %3 %4 %5 %6 %7 %8 %9
  144. rem Create beginning of subdirectory listing:
  145. echo echo off>$dirlist.bat
  146. if not exist $dirlist.bat goto nodirlist
  147. echo --- Create subdirectory listing (root not included), wait.....................
  148. ctty nul
  149. disk /d /b z:>>$dirlist.bat
  150. ctty con
  151. command/c$dirlist echo
  152. rem Process $DIRLIST.BAT with "%1 d:\path %2" lines into $FILLIST.BAT with
  153. rem "%2 %3 %4 %5 d:\path\%1 %6 %7 %8 %9" lines
  154. echo echo off>$fillist.bat
  155. if not exist $fillist.bat goto nofillist
  156. echo %%2 %%3 %%4 %%5 Z:\%%1 %%6 %%7 %%8 %%9>>$fillist.bat
  157. ctty nul
  158. command/c$dirlist command/c%0 .sub5
  159. ctty con
  160.  
  161. rem Create $FILSPEC.BAT containing "shift║%0 %1 filespec %2 %3 %4 %5 %6 %7 %8 %9"
  162. rem ('shift' in order not to output $FILSPEC as %0 when used later from REPLICA,
  163. rem  but REPLICA, to insert FILESPEC as %2 and to keep all other 7 parameters.)
  164. echo echo off>$filspec.bat
  165. if not exist $filspec.bat goto nofilspec
  166. echo shift>>$filspec.bat
  167. echo %%0 .filspec %%0 %%1 %2 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>>$filspec.bat
  168. echo --- transfer subdirectory structure $DIRLIST.BAT, filelist $FILLIST.BAT
  169. echo     and filespec $FILSPEC.BAT
  170. rem with only optional COM port and/or baudrate parameter
  171. command/c%0 .sub2 %0 %3 %4 %5 %6 %7 %8 %9
  172.  
  173. rem Process $DIRLIST.BAT with "%1 d:\path %2" lines into $ZIPLIST.BAT with
  174. rem "zip d:\path\%1 /[d:\path] %2 %3 %4 %5 %6 %7 %8" lines
  175. echo echo off>$ziplist.bat
  176. if not exist $ziplist.bat goto noziplist
  177. echo zip Z:\%%1 /[Z:\] %%2 %%3 %%4 %%5 %%6 %%7 %%8>>$ziplist.bat
  178. ctty nul
  179. command/c$dirlist command/c%0 .sub4
  180. ctty con
  181. echo --- transfer all files, wait for receiver creating subdir structure
  182. command/c%0 .sub6 %0 command/c$ziplist %2 %3 %4 %5 %6 %7 %8 %9
  183. echo --- Unlink server
  184. rem include all ZIP options
  185. command/c%0 .sub6 %0 zip /u %3 %4 %5 %6 %7 %8 %9
  186.  
  187. :finish
  188. for %%a in (%3 %4 %5 %6 %7 %8 %9) do if "%%a"==".d" goto delete
  189. for %%a in (%3 %4 %5 %6 %7 %8 %9) do if "%%a"==".D" goto delete
  190. goto unmount
  191.  
  192. :delete
  193. rem check whether to delete all successfully transferred files
  194. if not exist $filspec.bat goto unmount
  195.   echo --- Deleting file specification %2 within branch %1
  196.   command/c$fillist %2 command/c%0 .sub7
  197.   rem () can not remove the directory list from $DIRLIST.BAT:
  198.   rem 1. the directories should be processed in the reverse order, not possible;
  199.   rem 2. there may still be files in them if not the default of *.* was given;
  200.   rem 3. directories may be substituted or protected, not possible to remove.
  201.  
  202. :unmount
  203. subst z: /d >nul
  204. if exist $dirlist.bat del $dirlist.bat
  205. if exist $dirlist.bat echo delete $DIRLIST.BAT yourself.
  206. if exist $ziplist.bat del $ziplist.bat
  207. if exist $ziplist.bat echo delete $ZIPLIST.BAT yourself.
  208. if exist $fillist.bat del $fillist.bat
  209. if exist $fillist.bat echo delete $FILLIST.BAT yourself.
  210. if exist $filspec.bat del $filspec.bat
  211. if exist $filspec.bat echo delete $FILSPEC.BAT yourself.
  212. echo === Termination of CLONE ===
  213. goto end
  214.  
  215. :nodirlist
  216. echo *** Unable to create $DIRLIST.BAT.
  217. goto explain
  218. :nofillist
  219. echo *** Unable to create $FILLIST.BAT.
  220. goto explain
  221. :nofilspec
  222. echo *** Unable to create $FILSPEC.BAT.
  223. goto explain
  224. :noziplist
  225. echo *** Unable to create $ZIPLIST.BAT.
  226. :explain
  227. echo     Current default drive:directory may be full or the directory entry
  228. echo     table is full or the disk is write protected or it is an existing
  229. echo     subdirectory name. Take whatever precautions are necessary to solve
  230. echo     this (enable write, delete some redundant file(s)).
  231. goto unmount
  232.  
  233. :$dirlist
  234. echo *** Unable to delete (or overwrite later) $DIRLIST.BAT
  235. goto $explain
  236. :$ziplist
  237. echo *** Unable to delete (or overwrite later) $ZIPLIST.BAT
  238. goto $explain
  239. :$fillist
  240. echo *** Unable to delete (or overwrite later) $FILLIST.BAT
  241. goto $explain
  242. :$filspec
  243. echo *** Unable to delete (or overwrite later) $FILSPEC.BAT
  244. :$explain
  245. echo     File and/or disk may be write protected, unprotect it/them.
  246. goto end
  247.  
  248. :error1
  249. echo *** Illegal source path specification %1 ***
  250. goto beep
  251.  
  252. :no_z_nul
  253. echo *** Impossible to install auxiliary substituted drive Z:.
  254. echo     - Maybe the external DOS SUBST command is not available.
  255. echo     - Maybe the necessary line "LASTDRIVE=Z" lacks in CONFIG.SYS.
  256. echo     - Maybe an already substituted or network drive has been specified;
  257. echo       only logical drives may be specified.
  258. echo     - Maybe an original drive Z: is write protected.
  259. echo     - Maybe the disk with %1 is write protected.
  260. echo     - Or maybe a wrong syntax has been applied (see below).
  261. echo     Correct and try again.
  262. goto beep
  263.  
  264. :not_existing
  265. echo *** Specified «drive»«path» %1 does not exist or is write protected.
  266. echo     Remove eventual protection (for check). Program abort!
  267. goto beep
  268. :is_file
  269. echo *** Specified «drive»«path» %1 is a file, not a subdirectory.
  270. echo     Program abort!
  271. goto beep
  272. :beep
  273. echo 
  274. pause
  275.  
  276. :help
  277. echo Usage: "CLONE «drive»«path» [«filespec»] [options]" of subdirectory to
  278. echo               transfer, including all subdirectories below (branches),
  279. echo with   «drive»  = logical (not substituted) drive A..Y (not Z:),
  280. echo and    «path»   = complete pathname, without trailing \, unless root,
  281. echo and [«filespec»]= optional file specification, wildcard (default *.*),
  282. echo and   [options] = one or more of optional parameters below:
  283. echo              .s : skip initial test for temporary scratch files
  284. echo              .d : delete specified files after successful transfer
  285. echo            ( /1│/2│/3│/4 : COM port number
  286. echo            ( /P : prompt for each file
  287. echo   see also ( /N : no overwrite (default overwrite)
  288. echo   ZIP.DOC  ( /E : send only already existing files (useless in this case)
  289. echo            ( /T : overwrite only older files, not newer ones
  290. echo            ( /Bbaudrate : sets baudrate
  291. echo Example: "CLONE C:\" or "CLONE D:\WORK\TEXTS *.TXT /2 .S /t .d".
  292. echo.
  293. echo On the receiving end the following has to be entered:
  294. echo "REPLICA «drive»«path» [options]" of receiving subdirectory.
  295. goto end
  296.  
  297. :sub1
  298. shift
  299. shift
  300. rem Remove .s .S from parameters and restart batch file................
  301. for %%a in (s S) do if "%1"==".%%a" %0 .sub1 %0 %2 %3 %4 %5 %6 %7 %8 %9
  302. for %%a in (s S) do if "%2"==".%%a" %0 .sub1 %0 %1 %3 %4 %5 %6 %7 %8 %9
  303. for %%a in (s S) do if "%3"==".%%a" %0 .sub1 %0 %1 %2 %4 %5 %6 %7 %8 %9
  304. for %%a in (s S) do if "%4"==".%%a" %0 .sub1 %0 %1 %2 %3 %5 %6 %7 %8 %9
  305. for %%a in (s S) do if "%5"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %6 %7 %8 %9
  306. for %%a in (s S) do if "%6"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %5 %7 %8 %9
  307. for %%a in (s S) do if "%7"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %5 %6 %8 %9
  308. for %%a in (s S) do if "%8"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %5 %6 %7 %9
  309. for %%a in (s S) do if "%9"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %5 %6 %7 %8
  310. %0 .entry2 %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
  311. rem never pass here!
  312.  
  313. :sub2
  314. shift
  315. shift
  316. rem Remove /p /n /e /t /P /N /E /T .d .D temporarily from parameters and execute
  317. rem 'ZIP $DIRLIST.BAT,$FILLIST.BAT,$FILSPEC.BAT ...'
  318. rem only with Com port and Baudrate parameters
  319. for %%a in (p n e t P N E T) do if "%1"=="/%%a" %0 .sub2 %0 %2 %3 %4 %5 %6 %7
  320. for %%a in (p n e t P N E T) do if "%2"=="/%%a" %0 .sub2 %0 %1 %3 %4 %5 %6 %7
  321. for %%a in (p n e t P N E T) do if "%3"=="/%%a" %0 .sub2 %0 %1 %2 %4 %5 %6 %7
  322. for %%a in (p n e t P N E T) do if "%4"=="/%%a" %0 .sub2 %0 %1 %2 %3 %5 %6 %7
  323. for %%a in (p n e t P N E T) do if "%5"=="/%%a" %0 .sub2 %0 %1 %2 %3 %4 %6 %7
  324. for %%a in (p n e t P N E T) do if "%6"=="/%%a" %0 .sub2 %0 %1 %2 %3 %4 %5 %7
  325. for %%a in (p n e t P N E T) do if "%7"=="/%%a" %0 .sub2 %0 %1 %2 %3 %4 %5 %6
  326. for %%a in (d D) do if "%1"==".%%a" %0 .sub2 %0 %2 %3 %4 %5 %6 %7
  327. for %%a in (d D) do if "%2"==".%%a" %0 .sub2 %0 %1 %3 %4 %5 %6 %7
  328. for %%a in (d D) do if "%3"==".%%a" %0 .sub2 %0 %1 %2 %4 %5 %6 %7
  329. for %%a in (d D) do if "%4"==".%%a" %0 .sub2 %0 %1 %2 %3 %5 %6 %7
  330. for %%a in (d D) do if "%5"==".%%a" %0 .sub2 %0 %1 %2 %3 %4 %6 %7
  331. for %%a in (d D) do if "%6"==".%%a" %0 .sub2 %0 %1 %2 %3 %4 %5 %7
  332. for %%a in (d D) do if "%7"==".%%a" %0 .sub2 %0 %1 %2 %3 %4 %5 %6
  333. zip $dirlist.bat,$fillist.bat,$filspec.bat /[] %1 %2 %3 %4 %5 %6 %7
  334. if errorlevel 1 goto error2
  335.   echo === subdirectory structure $DIRLIST.BAT, filelist $FILLIST.BAT
  336.   echo     and filespec $FILSPEC.BAT successfully transferred
  337.   :recover1
  338.   rem      and return to calling point
  339.   goto end
  340.  
  341. :error2
  342. echo *** An error occurred while sending $DIRLIST.BAT, $FILLIST.BAT and $FILSPEC.BAT
  343. echo     (see above)
  344. goto recover1
  345.  
  346. :nofilespec
  347. rem %2 is empty or one of the parameters beginning with a '/' or /./
  348. rem Restart %0 with *.* as second parameter and continue from :file_spec
  349. echo --- Default file specification *.* assumed.
  350. %0 .sub3 %0 %1 *.* %2 %3 %4 %5 %6 %7 %8 %9
  351.  
  352. :sub3
  353. shift
  354. shift
  355. goto file_spec
  356.  
  357. :sub4
  358. echo zip %1\%%1 /[%1] %%2 %%3 %%4 %%5 %%6 %%7 %%8>>$ziplist.bat
  359. goto exit
  360.  
  361. :sub5
  362. echo %%2 %%3 %%4 %%5 %1\%%1 %%6 %%7 %%8 %%9>>$fillist.bat
  363. goto exit
  364.  
  365. :sub6
  366. shift
  367. shift
  368. rem Remove .d .D temporary from parameters and execute %1................
  369. for %%a in (d D) do if "%3"==".%%a" %0 .sub6 %0 %1 %2 %4 %5 %6 %7 %8 %9
  370. for %%a in (d D) do if "%4"==".%%a" %0 .sub6 %0 %1 %2 %3 %5 %6 %7 %8 %9
  371. for %%a in (d D) do if "%5"==".%%a" %0 .sub6 %0 %1 %2 %3 %4 %6 %7 %8 %9
  372. for %%a in (d D) do if "%6"==".%%a" %0 .sub6 %0 %1 %2 %3 %4 %5 %7 %8 %9
  373. for %%a in (d D) do if "%7"==".%%a" %0 .sub6 %0 %1 %2 %3 %4 %5 %6 %8 %9
  374. for %%a in (d D) do if "%8"==".%%a" %0 .sub6 %0 %1 %2 %3 %4 %5 %6 %7 %9
  375. for %%a in (d D) do if "%9"==".%%a" %0 .sub6 %0 %1 %2 %3 %4 %5 %6 %7 %8
  376. %1 %2 %3 %4 %5 %6 %7 %8 %9
  377. if errorlevel 1 goto error3
  378.   if not "%2"=="/u" echo === all files successfully transferred
  379.   if "%2"=="/u" echo === server unlinked successfully
  380.   :recover3
  381.   goto exit
  382.  
  383. :error3
  384. if not "%2"=="/u" echo *** An error occurred while sending files (see above)
  385. rem indicate failure to transfer files by removing $FILSPEC.BAT prematurely
  386. rem (errorlevel cannot be passed down to previous command level)
  387. if not "%2"=="/u" if exist $filspec.bat del $filspec.bat
  388. if "%2"=="/u" echo *** An error occurred while unlinking server (receiving end) (see above)
  389. if "%2"=="/u" echo     You may have to press ESC on the receiving end to finish !!!!!!!!!!!
  390. goto recover3
  391.  
  392. :sub7
  393. rem Original file specification does not need to be present in every branch:
  394. if not exist %2 goto end
  395. rem To automatically answer Y to eventual "Are you sure (Y/N)?" if original
  396. rem (default) file specification is *.* (here it is preceeded by the path):
  397. echo y|del %2>nul
  398. if not exist %2 goto end
  399. rem Check for successful deletion of %2 below branch %1
  400. echo.
  401. echo ***************************************************************************
  402. echo !!! Warning: target file specification %2 still exists!
  403. dir %2 /w /p
  404. echo     You may have to delete %2 yourself.
  405. pause
  406. goto end
  407.  
  408. :end
  409. :exit
  410.