home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / r / rcx10.zip / RCX.BAT < prev    next >
DOS Batch File  |  1993-01-29  |  11KB  |  264 lines

  1. @echo off
  2.  rem For DOS«3.3 one may change 'call' into 'command/c' or use the external CALL
  3.  rem program (by me) and remove the '@' before the 'echo off'.
  4. ctty con
  5. for %%N in (0 1) do if "%1"==".rcx%%N" goto _RCX_%%N
  6.  rem if "%1"==".rcx0" goto _RCX_0 ──┤
  7.  rem if "%1"==".rcx1" goto _RCX_1 ──┘
  8.  
  9. if "%1"=="" goto no_log
  10. if "%2"=="" goto no_log
  11.  rem Open/append log file RCX.LOG during the first initial run only:
  12. echo ========================== RCX.LOG ==========================>>rcx.log
  13. echo.|date|find "is">>rcx.log
  14. echo.|time|find "is">>rcx.log
  15. echo COMMAND LINE: %0 %1 %2 %3 %4 %5 %6 %7 %8 %9>>rcx.log
  16.  
  17. :no_log
  18. goto _RCX
  19.  
  20. :_RCX_0
  21. shift
  22. shift
  23. :_RCX
  24.  rem Change root '\' as target dir into '\.' for correct further processing
  25. if "%1"=="\" goto is_root
  26. for %%f 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"=="%%f:\" goto is_root
  27. for %%f 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"=="%%f:\" goto is_root
  28. goto continue
  29.  
  30. :is_root
  31. %0 .rcx0 %0 %1. %2 %3 %4 %5 %6 %7 %8 %9
  32. :continue
  33.  rem ....................... process DELETE parameter ........................
  34. if "%1"=="" goto DelProcessed
  35. if "%2"=="" goto DelProcessed
  36.  
  37.  rem If parameter .d or .D is specified somewhere, make it the second one '.d'
  38.  rem If it has not been specified make the second parameter '.n' of not '.nested'
  39. if "%2"==".n" goto DelProcessed
  40. for %%d in (   .D) do if "%%d"=="%2" %0 .rcx0 %0 %1 .d %3 %4 %5 %6 %7 %8 %9
  41. for %%d in (.d .D) do if "%%d"=="%3" %0 .rcx0 %0 %1 .d %2 %4 %5 %6 %7 %8 %9
  42. for %%d in (.d .D) do if "%%d"=="%4" %0 .rcx0 %0 %1 .d %2 %3 %5 %6 %7 %8 %9
  43. for %%d in (.d .D) do if "%%d"=="%5" %0 .rcx0 %0 %1 .d %2 %3 %4 %6 %7 %8 %9
  44. for %%d in (.d .D) do if "%%d"=="%6" %0 .rcx0 %0 %1 .d %2 %3 %4 %5 %7 %8 %9
  45. for %%d in (.d .D) do if "%%d"=="%7" %0 .rcx0 %0 %1 .d %2 %3 %4 %5 %6 %8 %9
  46. for %%d in (.d .D) do if "%%d"=="%8" %0 .rcx0 %0 %1 .d %2 %3 %4 %5 %6 %7 %9
  47. for %%d in (.d .D) do if "%%d"=="%9" %0 .rcx0 %0 %1 .d %2 %3 %4 %5 %6 %7 %8
  48. if not "%2"==".nested" if not "%2"==".d" %0 .rcx0 %0 %1 .n %2 %3 %4 %5 %6 %7 %8
  49.  
  50. :DelProcessed
  51.  rem Suppress initial message with nested runs (recursive loops), specified by '.nested'
  52. if "%2"==".nested" goto begin1
  53.  
  54. echo RCX ReCursive .arc/.zipfile eXtractor by Jim Groeneveld, vs. 1.0, 29/1-93.
  55. echo ------------------------------------------------------------------------------
  56. echo Extracts one or more archives (.ARC/.ZIPfiles) into subdirectories named by
  57. echo the file_name part of the archive (or 'filename.DIR' if the archive has no
  58. echo extension itself) relative to the destination directory.
  59. echo ZIPfiles are extracted including their eventually stored directory structure.
  60. echo Nested archives (.ARC/.ZIPfiles) are recursively extracted into subdirectories
  61. echo named by the embedded .ARC/.ZIPfiles relative to the parent ARC/ZIPfile.
  62.  rem (DOS 2+)
  63. echo.
  64. if "%1"=="" goto helpRCX
  65. if "%2"=="" goto helpRCX
  66. if "%1"=="?" goto helpRCX
  67. if "%1"=="/?" goto helpRCX
  68. if "%1"=="-?" goto helpRCX
  69. if "%1"=="/h" goto helpRCX
  70. if "%1"=="/H" goto helpRCX
  71.  
  72. :begin1
  73. echo --- Check existence of target_path %1 ---
  74.  REM 'if not exist %1\nul goto no_target' REMOVE (replaced by 11 lines below)
  75. if exist %1\*.* goto begin2
  76.  rem If command above did not find anything the subdir might exist but be empty.
  77.  rem Avoid screen output if redirection below does not succeed: CTTY NUL.
  78. ctty nul
  79.  rem write dummy file to the path %1 to check its existence
  80. rem>%1\$0-BYTE$.NUL
  81. ctty con
  82. if not exist %1\$0-BYTE$.NUL goto no_target
  83.  rem The drive:path %1 does not exist (anymore).
  84.  rem Or the disk may be write protected.
  85. del %1\$0-BYTE$.NUL
  86.  
  87. :begin2
  88.  rem --- Process archive specifications %3 %4 %5 %6 %7 %8 %9 ---
  89. ctty nul
  90. for %%f in (%3 %4 %5 %6 %7 %8 %9) do call %0 .rcx1 %0 %1\ %2 %%f
  91.  rem Try to add extensions .ARC and .ZIP to any file name (wildcard) if not nested:
  92. if "%2"==".nested" goto nested
  93. if exist %3.arc for %%f in (%3.ARC) do call %0 .rcx1 %0 %1\ %2 %%f
  94. if exist %4.arc for %%f in (%4.ARC) do call %0 .rcx1 %0 %1\ %2 %%f
  95. if exist %5.arc for %%f in (%5.ARC) do call %0 .rcx1 %0 %1\ %2 %%f
  96. if exist %6.arc for %%f in (%6.ARC) do call %0 .rcx1 %0 %1\ %2 %%f
  97. if exist %7.arc for %%f in (%7.ARC) do call %0 .rcx1 %0 %1\ %2 %%f
  98. if exist %8.arc for %%f in (%8.ARC) do call %0 .rcx1 %0 %1\ %2 %%f
  99. if exist %9.arc for %%f in (%9.ARC) do call %0 .rcx1 %0 %1\ %2 %%f
  100. if exist %3.zip for %%f in (%3.zip) do call %0 .rcx1 %0 %1\ %2 %%f
  101. if exist %4.zip for %%f in (%4.zip) do call %0 .rcx1 %0 %1\ %2 %%f
  102. if exist %5.zip for %%f in (%5.zip) do call %0 .rcx1 %0 %1\ %2 %%f
  103. if exist %6.zip for %%f in (%6.zip) do call %0 .rcx1 %0 %1\ %2 %%f
  104. if exist %7.zip for %%f in (%7.zip) do call %0 .rcx1 %0 %1\ %2 %%f
  105. if exist %8.zip for %%f in (%8.zip) do call %0 .rcx1 %0 %1\ %2 %%f
  106. if exist %9.zip for %%f in (%9.zip) do call %0 .rcx1 %0 %1\ %2 %%f
  107.  
  108. :nested
  109. ctty con
  110. if "%2"==".nested" goto endRCX
  111.  rem Final termination of program, report here
  112. echo === RCX terminated normally; see log file RCX.LOG ===
  113. echo.>>rcx.log
  114. goto endRCX
  115.  
  116. :no_target
  117. echo --- Trying to create target_path %1 ---
  118. md %1
  119.  REM 'if exist %1\nul goto begin2' REMOVE (replaced by about 10 lines below)
  120.  rem Avoid screen output if redirection below does not succeed: CTTY NUL.
  121. ctty nul
  122.  rem write dummy file to the path %1 to check its existence
  123. rem>%1\$0-BYTE$.NUL
  124. ctty con
  125. if exist %1\$0-BYTE$.NUL goto Delete_1
  126. echo *** Target path %1 does not exist and cannot be created. ABORT.
  127. echo *** Target path %1 does not exist and cannot be created. ABORT.>>rcx.log
  128. goto nested
  129.  
  130. :Delete_1
  131.  rem Delete dummy check file
  132. del %1\$0-BYTE$.NUL
  133. goto begin2
  134.  
  135. :helpRCX
  136. echo Syntax: RCX «target_path» «source_path_file» [«source_path_file» [..]] [.d]
  137. echo in which
  138. echo «target_path»      = [d:]path of destination (drive/)directory, or relative
  139. echo                                 to current ('.') one, excl. trailing '\'!
  140. REM -------- (REDUNDANT) ---------   Specify root '\' eventually as '\.'.
  141. echo «source_path_file» = [d:][path\]filename of ARC/ZIPfile(s) to extract (up to 7)
  142. echo                                 (wildcards allowed; extensions redundant)
  143. echo                                 Avoid files with the same file name part and
  144. echo                                 different archive ext's (.ARC and .ZIP).
  145. echo .d                 = parameter indicating deletion of original archive
  146. echo                                 (.ARC/.ZIP) after extraction.
  147. echo                      Embedded ARC/ZIPfiles always are automatically deleted.
  148. :endRCX
  149. goto exit
  150.  
  151. :_RCX_1
  152. shift
  153. shift
  154.  rem _RCX_1 receives (1) target_path, (2) deletion option (.d or .n or .nested)
  155.  rem and (3) single file specification
  156.  rem If parameter (4) exists it is the already discriminated filename part
  157.  rem If parameter (5) exists it is the already discriminated extension or 'none'
  158.  rem In fact %3 is never expected to be empty, but though:
  159. if "%3"=="" goto endRCX_1
  160.  REM *** for %%f in (.d .D .nested .d.arc .D.arc .d.zip .D.zip) do if "%2"=="%%f" goto endRCX_1
  161.  rem %3 may not exist if a single file name (no wildcard) was specified
  162. if not "%4"=="" goto make_sub
  163. if not exist %3 goto not_exist
  164.    rem create subdirectory from single file specification:
  165.    rem Uility GETFNX discriminates a.o. the filename
  166.   echo --- Search for filename part in %3 ---
  167.   call GETFNX %3
  168.   if not exist GETFNX2.BAT goto nogetfnx
  169.   GETFNX2 %0 .rcx1 %0 %1 %2 %3
  170.    rem -------------- loopback
  171.  
  172. :nogetfnx
  173. echo *** Directory name can not be determined. Leave archive in place.
  174.  rem (or some other solution: issuing standard directory names)
  175. goto exit
  176.  
  177. :make_sub
  178.  rem If no extension was specified with the source file make the subdirectory name,
  179.  rem in which to extract, equal to the file name and the extension 'DIR' and
  180.  rem add a dot after the original file name in order to avoid PKUNPAK and PKUNZIP
  181.  rem to assume their implicit extension .ARC or .ZIP:
  182. if "%5"=="none" %0 .rcx1 %0 %1 %2 %3. %4.DIR NONE
  183.  rem Second loop: delete scratch file GETFNX2.BAT, used in first loop
  184. if exist GETFNX2.BAT del GETFNX2.BAT
  185.  rem make subdirectory (and test for success); first test for existence
  186.  REM 'if exist %1%4\nul goto extract' REMOVE (replaced by 14 lines below)
  187. if exist %1%4\*.* goto extract
  188.  rem If command above did not find anything the subdir might exist but be empty.
  189.  rem Avoid screen output if redirection below does not succeed: CTTY NUL.
  190. ctty nul
  191.  rem write dummy file to the path %1%4 to check its existence
  192. rem>%1%4\$0-BYTE$.NUL
  193. ctty con
  194. if exist %1%4\$0-BYTE$.NUL goto Delete_2
  195.  rem The drive:path %1%4 does not exist.
  196. goto create
  197.  
  198. :Delete_2
  199.  rem Delete dummy check file
  200. del %1%4\$0-BYTE$.NUL
  201. goto extract
  202.  
  203. :create
  204. echo --- Trying to create subdirectory %1%4 ---
  205. md %1%4
  206.  REM 'if exist %1%4\nul goto extract' REMOVE (replaced by 14 lines below)
  207. if exist %1%4\*.* goto extract
  208.  rem If command above did not find anything the subdir might exist but be empty.
  209.  rem Avoid screen output if redirection below does not succeed: CTTY NUL.
  210. ctty nul
  211.  rem write dummy file to the path %1%4 to check its existence
  212. rem>%1%4\$0-BYTE$.NUL
  213. ctty con
  214. if exist %1%4\$0-BYTE$.NUL goto Delete_2
  215.  rem The drive:path %1%4 does not exist.
  216. echo *** Subdirectory %1%4 could not be created, archive %3 not extracted and deleted.
  217. echo *** Subdirectory %1%4 could not be created, archive %3 not extracted and deleted.>>rcx.log
  218. goto endRCX_1
  219.  
  220. :not_exist
  221. echo *** File %3 does not exist, no action.
  222. echo *** File %3 does not exist, no action.>>rcx.log
  223. goto endRCX_1
  224.  
  225. :extract
  226. echo --- Extract archive %3 into subdirectory %1%4 ---
  227. for %%a in (arc ARC) do if "%5"=="%%a" goto arc_direct
  228.  rem Avoid files with the same file name part and different archive ext's (.ARC and .ZIP).
  229. pkunzip -d -JHSR %3 %1%4
  230. if not errorlevel 1 goto del_archive
  231.  
  232. :arc_direct
  233. pkunpak -x %3 %1%4
  234. if not errorlevel 1 goto del_archive
  235.  rem Errorlevel is at least 1
  236. echo *** An error occurred while extracting archive %3, not deleted!
  237. echo *** An error occurred while extracting archive %3, not deleted!>>rcx.log
  238. goto restart
  239.  
  240. :del_archive
  241. echo !!! Archive %3 extracted successfully>>rcx.log
  242. if "%2"==".n" goto restart
  243.  rem else %2 is either '.d' or '.nested' indicating deletion
  244. echo Auto-deletion of %3
  245. del %3
  246. if exist %3 goto not_deleted
  247. echo !!! Archive %3 deleted>>rcx.log
  248. goto restart
  249.  
  250. :not_deleted
  251. echo *** Archive %3 could not be deleted automatically.
  252. echo *** Archive %3 could not be deleted automatically.>>rcx.log
  253.  
  254. :restart
  255.  rem Restart RCX specifying target_SUBdirectory as both (relative) target and source recursively
  256. echo --- Process eventual archives (ARC/ZIPfiles) in %1%4 ---
  257. ctty nul
  258. call %0 .rcx0 %0 %1%4 .nested %1%4\*.ARC %1%4\*.ZIP
  259. ctty con
  260. :endRCX_1
  261.  rem goto exit
  262.  
  263. :exit
  264.