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 / REPLICA.BAT < prev    next >
DOS Batch File  |  1993-01-07  |  14KB  |  392 lines

  1. echo off
  2. if "%1"==".entry1" goto entry1
  3. if "%1"==".entry2" goto entry2
  4. if "%1"==".sub1" goto sub1
  5. if "%1"==".sub2" goto sub2
  6. if "%1"==".filspec" goto filspec
  7. if "%1"==".sub4" goto sub4
  8. if "%2"==".sub5" goto sub5
  9. if "%1"==".sub6" goto sub6
  10.  
  11. echo REPLICA vs. 1.1 receives a complete drive, or a part of it (branch) serially
  12. echo from another machine into a specific subdirectory. (c) 1993, Jim Groeneveld, NL
  13. echo.
  14. rem Necessary auxiliary files: SUBST.*, FIND.* (DOS) and 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. :entry1
  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 $fillist.bat goto no_fillist
  43.   echo *** Temporary file $FILLIST.BAT already exists, cannot proceed;
  44.   echo     remove or rename $FILLIST.BAT or specify '.s' option.
  45.   goto end
  46. :no_fillist
  47. if not exist $filspec.bat goto no_filspec
  48.   echo *** Temporary file $FILSPEC.BAT already exists, cannot proceed;
  49.   echo     remove or rename $FILSPEC.BAT or specify '.s' option.
  50.   goto end
  51.  
  52. :no_filspec
  53. if exist $dirlist.bat del $dirlist.bat
  54. if exist $dirlist.bat goto $dirlist
  55. if exist $fillist.bat del $fillist.bat
  56. if exist $fillist.bat goto $fillist
  57. if exist $filspec.bat del $filspec.bat
  58. if exist $filspec.bat goto $filspec
  59.  
  60. rem Search %2 for optional legal parameter:
  61. if "%2"=="" goto OK_2
  62. for %%f in (/%2) do if "%%f"=="/" goto OK_2
  63. for %%f in (/%2) do if "%%f"=="." goto OK_2
  64. goto error2
  65.  
  66. :OK_2
  67. rem if "%1"=="\" goto error1         These subst path specifications appear to
  68. rem if "%1"=="." goto error1         work correctly, as does any relative path
  69. rem if "%1"==".." goto error1        specification, at least with DOS 3.3 .
  70. 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
  71. 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
  72. 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
  73. 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
  74. if "%1"=="z:\" goto error1
  75. if "%1"=="Z:\" goto error1
  76.  
  77. 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
  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) do if "%1"=="%%a:\" goto begin
  79. if exist %1 goto is_file
  80. if exist %1\$chkpath.nul del %1\$chkpath.nul
  81. if exist %1\$chkpath.nul goto 1_exists
  82. if exist %1\*.* goto begin
  83.   ctty nul
  84.   rem>%1\$chkpath.nul
  85.   ctty con
  86.   if not exist %1\$chkpath.nul goto not_existing
  87.   :begin0
  88.   if exist %1\$chkpath.nul del %1\$chkpath.nul
  89. :begin
  90. if exist Z:\*.* goto z_exists
  91.   ctty nul
  92.   rem>Z:\$chkpath.nul
  93.   ctty con
  94.   if not exist Z:\$chkpath.nul goto nosubstz
  95.     del Z:\$chkpath.nul
  96.  
  97. :z_exists
  98. echo --- Existing substitution or network assignment drive of Z: will be lost;
  99. echo     drive Z will be temporarily substituted as %1
  100. echo     Restore original substitution after termination of this program:
  101. subst|find "Z:"
  102. net use|find "Z:"
  103. echo (Ignore eventual "Bad command or file name" above...........)
  104.  
  105. :nosubstz
  106. rem If Z: is write protected its existence can not be checked. So to be
  107. rem sure Z: is being freed below from substitution or network assignment.
  108. subst z: /d >nul
  109. rem disconnect drive Z: from network, ignore eventual error message..........
  110. ctty nul
  111. net use z: /d >nul
  112. ctty con
  113.  
  114. rem check whether Z: now indeed does not exist
  115. if not exist Z:\*.* goto mount
  116.   ctty nul
  117.   rem>Z:\$chkpath.nul
  118.   ctty con
  119.   if not exist Z:\$chkpath.nul goto mount
  120.     del Z:\$chkpath.nul
  121.     echo *** Existing drive Z:\ could not be disconnected successfully.
  122.     echo     It still may be ASSIGNed or otherwise existing. Program abort!
  123.     goto beep
  124.  
  125. :mount
  126. rem substitute Z: to specified drive:\path to transfer
  127. subst z: %1 >nul
  128. rem and check whether substitution succeeded
  129. if exist Z:\$chkpath.nul del Z:\$chkpath.nul
  130. if exist Z:\$chkpath.nul goto no_z_nul
  131. if exist Z:\*.* goto begin2
  132.   ctty nul
  133.   rem>Z:\$chkpath.nul
  134.   ctty con
  135.   if not exist Z:\$chkpath.nul goto no_z_nul
  136.     del Z:\$chkpath.nul
  137.  
  138. :begin2
  139. echo --- receive subdirectory structure $DIRLIST.BAT, filelist $FILLIST.BAT
  140. echo     and filespec $FILSPEC.BAT (in current drive\dir)
  141. rem without eventual parameter .x
  142. command/c%0 .sub2 %0 %2 %3 %4 %5 %6 %7 %8 %9
  143. if not exist $dirlist.bat goto nodirlist
  144. if not exist $fillist.bat goto nofillist
  145. if not exist $filspec.bat goto nofilspec
  146. rem restart with obtained filespec from $FILSPEC.BAT as %2
  147. $filspec %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
  148.  
  149. :file_spec
  150. echo --- Replicating branch: %1, file specification: %2
  151. if not "%3"=="" echo     Additional option(s): %3 %4 %5 %6 %7 %8 %9
  152. echo --- create subdir structure from list (in specified drive\dir)
  153. command/c$dirlist echo
  154. ctty nul
  155. command/c$dirlist md
  156. ctty con
  157. echo --- check whether they exist (already, if unable to create)
  158. command/c$dirlist %0 .sub5
  159. rem eventual check for existing target files if _no_ '.x' parameter
  160. for %%a in (%3 %4 %5 %6 %7 %8 %9) do if "%%a"==".x" goto repeat_2
  161. for %%a in (%3 %4 %5 %6 %7 %8 %9) do if "%%a"==".X" goto repeat_2
  162.   goto chkfiles
  163.  
  164. :repeat_2
  165. %0 .sub4 %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
  166. rem never pass here!
  167.  
  168. :chkfiles
  169. command/c$fillist %2 command/c%0 .sub6
  170. goto no-chk
  171.  
  172. :entry2
  173. shift
  174. shift
  175. :no-chk
  176. echo --- receive files (in specified drive\dir)
  177. zip /s %3 %4 %5 %6 %7 %8 %9
  178. if errorlevel 1 goto error4
  179. echo === all files successfully received and server successfully unlinked
  180. rem server will be unlinked by client
  181.  
  182. :finish
  183. subst z: /d >nul
  184. if exist $dirlist.bat del $dirlist.bat
  185. if exist $dirlist.bat echo delete $DIRLIST.BAT yourself.
  186. if exist $fillist.bat del $fillist.bat
  187. if exist $fillist.bat echo delete $FILLIST.BAT yourself.
  188. if exist $filspec.bat del $filspec.bat
  189. if exist $filspec.bat echo delete $FILSPEC.BAT yourself.
  190. echo === Termination of REPLICA ===
  191. goto end
  192.  
  193. :$dirlist
  194. echo *** Unable to delete (or overwrite later) $DIRLIST.BAT
  195. goto $explain
  196. :$fillist
  197. echo *** Unable to delete (or overwrite later) $FILLIST.BAT
  198. goto $explain
  199. :$filspec
  200. echo *** Unable to delete (or overwrite later) $FILSPEC.BAT
  201. :$explain
  202. echo     File and/or disk may be write protected, unprotect it/them.
  203. goto end
  204.  
  205. :error1
  206. echo *** Illegal target path specification %1 ***
  207. goto beep
  208. :error2
  209. echo *** Illegal parameter %2 ***
  210. goto beep
  211.  
  212. :error4
  213. if errorlevel 128 goto finish
  214. echo *** An error occurred while receiving all files (see above)
  215. echo     Abort sending end manually if not already automatically
  216. echo     and try again (maybe using a different speed).
  217. goto finish
  218.  
  219. :nodirlist
  220. echo *** $DIRLIST.BAT apparently not received. Cannot proceed. Program abort!
  221. goto finish
  222. :nofillist
  223. echo *** $FILLIST.BAT apparently not received. Cannot proceed. Program abort!
  224. goto finish
  225. :nofilspec
  226. echo *** $FILSPEC.BAT apparently not received. Cannot proceed. Program abort!
  227. goto finish
  228.  
  229. :no_z_nul
  230. echo *** Impossible to install auxiliary substituted drive Z:.
  231. echo     - Maybe the external DOS SUBST command is not available.
  232. echo     - Maybe the necessary line "LASTDRIVE=Z" lacks in CONFIG.SYS.
  233. echo     - Maybe an already substituted or network drive has been specified;
  234. echo       only logical drives may be specified.
  235. echo     - Maybe an original drive Z: is write protected.
  236. echo     - Maybe the disk with %1 is write protected.
  237. echo     - (maybe only temporary check file $CHKPATH.NUL is write protected).
  238. echo     - Or maybe a wrong syntax has been applied (see below).
  239. echo     Correct and try again.
  240. goto beep
  241.  
  242. :not_existing
  243. ctty nul
  244. md %1
  245. rem>%1\$chkpath.nul
  246. ctty con
  247. if exist %1\$chkpath.nul goto begin0
  248.   echo *** Specified «drive»«path» %1 does not exist
  249.   echo     and cannot be created or the disk may be write protected.
  250.   echo     Remove eventual protection or create %1 manually firstly.
  251.   echo     Program abort!
  252.   goto beep
  253.  
  254. :1_exists
  255. echo *** Specified «drive»«path» %1 is write protected
  256. echo     (or only temporary check file $CHKPATH.NUL is write protected).
  257. echo     Remove protection. Program abort!
  258. goto beep
  259. :is_file
  260. echo *** Specified «drive»«path» %1 is a file, not a subdirectory.
  261. echo     Program abort!
  262. goto beep
  263. :beep
  264. echo 
  265.  
  266. :help
  267. echo Usage: "REPLICA «drive»«path» [options]" of receiving subdirectory,
  268. echo with   «drive»  = logical (not substituted) drive A..Y (not Z:),
  269. echo and    «path»   = complete pathname, without trailing \, unless root,
  270. echo and   [options] = one or more of optional parameters below:
  271. echo              .s : skip initial test for temporary scratch files
  272. echo              .x : skip check for existing files in target directories
  273. echo   see also ( /1│/2│/3│/4 : COM port number
  274. echo   ZIP.DOC  ( /Bbaudrate : sets baudrate
  275. echo Example: "REPLICA C:\" or "REPLICA D:\WORK\TEXTS /2 .X".
  276. echo.
  277. echo On the sending end the following has to be entered:
  278. echo "CLONE «drive»«path» [«filespec»] [options]" of subdirectory to transfer.
  279. goto end
  280.  
  281. :sub1
  282. shift
  283. shift
  284. rem Remove .s .S from parameters and restart batch file................
  285. for %%a in (s S) do if "%1"==".%%a" %0 .sub1 %0 %2 %3 %4 %5 %6 %7 %8 %9
  286. for %%a in (s S) do if "%2"==".%%a" %0 .sub1 %0 %1 %3 %4 %5 %6 %7 %8 %9
  287. for %%a in (s S) do if "%3"==".%%a" %0 .sub1 %0 %1 %2 %4 %5 %6 %7 %8 %9
  288. for %%a in (s S) do if "%4"==".%%a" %0 .sub1 %0 %1 %2 %3 %5 %6 %7 %8 %9
  289. for %%a in (s S) do if "%5"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %6 %7 %8 %9
  290. for %%a in (s S) do if "%6"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %5 %7 %8 %9
  291. for %%a in (s S) do if "%7"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %5 %6 %8 %9
  292. for %%a in (s S) do if "%8"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %5 %6 %7 %9
  293. for %%a in (s S) do if "%9"==".%%a" %0 .sub1 %0 %1 %2 %3 %4 %5 %6 %7 %8
  294. %0 .entry1 %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
  295. rem never pass here!
  296.  
  297. :sub2
  298. shift
  299. shift
  300. rem Remove .x .X temporary from parameters and execute ZIP................
  301. for %%a in (x X) do if "%1"==".%%a" %0 .sub2 %0 %2 %3 %4 %5 %6 %7 %8
  302. for %%a in (x X) do if "%2"==".%%a" %0 .sub2 %0 %1 %3 %4 %5 %6 %7 %8
  303. for %%a in (x X) do if "%3"==".%%a" %0 .sub2 %0 %1 %2 %4 %5 %6 %7 %8
  304. for %%a in (x X) do if "%4"==".%%a" %0 .sub2 %0 %1 %2 %3 %5 %6 %7 %8
  305. for %%a in (x X) do if "%5"==".%%a" %0 .sub2 %0 %1 %2 %3 %4 %6 %7 %8
  306. for %%a in (x X) do if "%6"==".%%a" %0 .sub2 %0 %1 %2 %3 %4 %5 %7 %8
  307. for %%a in (x X) do if "%7"==".%%a" %0 .sub2 %0 %1 %2 %3 %4 %5 %6 %8
  308. for %%a in (x X) do if "%8"==".%%a" %0 .sub2 %0 %1 %2 %3 %4 %5 %6 %7
  309. zip /r[] %1 %2 %3 %4 %5 %6 %7 %8
  310. if errorlevel 1 goto error3
  311.   echo === subdirectory structure $DIRLIST.BAT, filelist $FILLIST.BAT
  312.   echo     and filespec $FILSPEC.BAT successfully received
  313.   :recover1
  314.   goto end
  315.  
  316. :error3
  317. echo *** An error occurred while sending $DIRLIST.BAT, $FILLIST.BAT and $FILSPEC.BAT
  318. echo     (see above)
  319. goto recover1
  320.  
  321. :filspec
  322. shift
  323. shift
  324. goto file_spec
  325.  
  326. :sub4
  327. shift
  328. shift
  329. rem Remove .x .X from parameters and restart batch file................
  330. for %%a in (x X) do if "%3"==".%%a" %0 .sub4 %0 %1 %2 %4 %5 %6 %7 %8 %9
  331. for %%a in (x X) do if "%4"==".%%a" %0 .sub4 %0 %1 %2 %3 %5 %6 %7 %8 %9
  332. for %%a in (x X) do if "%5"==".%%a" %0 .sub4 %0 %1 %2 %3 %4 %6 %7 %8 %9
  333. for %%a in (x X) do if "%6"==".%%a" %0 .sub4 %0 %1 %2 %3 %4 %5 %7 %8 %9
  334. for %%a in (x X) do if "%7"==".%%a" %0 .sub4 %0 %1 %2 %3 %4 %5 %6 %8 %9
  335. for %%a in (x X) do if "%8"==".%%a" %0 .sub4 %0 %1 %2 %3 %4 %5 %6 %7 %9
  336. for %%a in (x X) do if "%9"==".%%a" %0 .sub4 %0 %1 %2 %3 %4 %5 %6 %7 %8
  337. %0 .entry2 %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
  338. rem never pass here!
  339.  
  340. :sub5
  341. if exist %1\*.* goto end
  342. if exist %1 goto is-file
  343.   ctty nul
  344.   rem>%1\$chkpath.nul
  345.   ctty con
  346.   if not exist %1\$chkpath.nul goto not-existing
  347.   del %1\$chkpath.nul
  348.   rem %1 is an existing directory
  349.   goto end
  350.  
  351. :is-file
  352. echo.
  353. echo ***************************************************************************
  354. echo *** Replicated specification %1 is an existing file name.
  355. echo     Transferring files to this "subdirectory" just hereafter
  356. echo     will _NOT_ succeed! REPLICA will continue after you
  357. pause
  358. goto end
  359.  
  360. :not-existing
  361. echo.
  362. echo ***************************************************************************
  363. echo *** Replicated specification %1
  364. echo     could not be created or is write protected.
  365. echo     Transferring files to this "subdirectory" just hereafter
  366. echo     probably will _NOT_ succeed! REPLICA will continue after you
  367. pause
  368. goto end
  369.  
  370. :sub6
  371. if not exist %2 goto end
  372. echo.
  373. echo ***************************************************************************
  374. echo !!! Warning: target file specification %2 already exists!
  375. dir %2 /w /p
  376. pause
  377. echo.
  378. echo IF YOU HAVE NOT SPECIFIED THE '/N' OR '/P' PARAMETER ON THE OTHER END (CLONE)
  379. echo THESE FILES MAY BE OVERWRITTEN!
  380. echo IF YOU WISH TO ABORT NOW PRESSING ^C OR Ctrl-Break WILL _NOT_ HELP!
  381. echo YOU CAN ONLY SWITCH OFF YOUR COMPUTER _NOW_ AND TRY AGAIN DIFFERENTLY.
  382. echo IN THAT CASE PRESS 'ESC' ON THE OTHER END AS MANY TIMES AS NECESSARY TO
  383. echo FINISH CLONE OR SWITCH IT OFF TOO AND RESTART.
  384. echo.
  385. echo To avoid these checks and resulting messages specify '.x' option next time.
  386. echo.
  387. echo If you think everything is OK (files may be overwritten or won't) then
  388. pause
  389. goto end
  390.  
  391. :end
  392.