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.B2C < prev    next >
Text File  |  1993-01-29  |  13KB  |  337 lines

  1. @echo off
  2.  rem The DOS internal CTTY command does not seem to be effective if compiled.
  3.  rem ctty con
  4. for %%N in (0 1) do if "%1"==".rcx%%N" goto _RCX_%%N
  5.  rem if "%1"==".rcx0" goto _RCX_0 ──┤
  6.  rem if "%1"==".rcx1" goto _RCX_1 ──┘
  7. if "%1"==".aux" goto CreateAux
  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. if exist rcx.log goto AppendLog
  13.  rem Compiled program can not append to non-existing output, so create it now:
  14.   rem>rcx.log
  15. :AppendLog
  16. echo ========================== RCX.LOG ==========================>>rcx.log
  17. echo.|date|find "is">>rcx.log
  18. echo.|time|find "is">>rcx.log
  19. echo COMMAND LINE: %0 %1 %2 %3 %4 %5 %6 %7 %8 %9>>rcx.log
  20.  rem Creation of auxiliary file in separate shelled run, because otherwise
  21.  rem IF COMPILED WITH BAT2EXEC vs. 1.5 THIS PROGRAM SUFFERS FROM A SEVERE BUG
  22.  rem THAT DEMONSTRATES ITSELF BY TRYING TO WRITE TO THE STANDARD PRINTER PORT.
  23. rem SO COMPILING THIS PROGRAM IS NOT RECOMMENDED! YET THIS SOURCE HAS BEEN
  24. rem INCLUDED FOR COMPILING WITH OTHER OR NEWER BATCH FILE COMPILERS.
  25. %0 .aux
  26.  
  27. :no_log
  28. goto _RCX
  29.  
  30. :CreateAux
  31.  rem Create auxiliary file $RCX$.BAT in current directory to use during the
  32.  rem recursive process, because otherwise each nested level would want its own,
  33.  rem yet active copy of the batch file GETFNX2, generated by GETFNX, while that
  34.  rem one is being rewritten during nesting for each potential file to extract.
  35.  rem The GETFNX2 batch file passes control to this auxiliary file (that remains
  36.  rem unchanged, and still may be active for many levels at the same time) and
  37.  rem thus may be rewritten as often as desired. This auxiliary file should be
  38.  rem removed at the end of the program.
  39. echo echo off>$RCX$.BAT
  40. echo shift>>$RCX$.BAT
  41. echo %%0 %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>>$RCX$.BAT
  42. goto exit
  43.  
  44. :_RCX_0
  45. shift
  46. shift
  47. :_RCX
  48.  rem Change root '\' as target dir into '\.' for correct further processing
  49. if "%1"=="\" goto is_root
  50. 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
  51. 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
  52. goto continue
  53.  
  54. :is_root
  55. %0 .rcx0 %0 %1. %2 %3 %4 %5 %6 %7 %8 %9
  56. goto exit
  57.  
  58. :continue
  59.  rem ....................... process DELETE parameter ........................
  60. if "%1"=="" goto DelProcessed
  61. if "%2"=="" goto DelProcessed
  62.  
  63.  rem If parameter .d or .D is specified somewhere, make it the second one '.d'
  64.  rem If it has not been specified make the second parameter '.n' of not '.nested'
  65. if "%2"==".n" goto DelProcessed
  66. for %%d in (   .D) do if "%%d"=="%2" goto d2
  67. for %%d in (.d .D) do if "%%d"=="%3" goto d3
  68. for %%d in (.d .D) do if "%%d"=="%4" goto d4
  69. for %%d in (.d .D) do if "%%d"=="%5" goto d5
  70. for %%d in (.d .D) do if "%%d"=="%6" goto d6
  71. for %%d in (.d .D) do if "%%d"=="%7" goto d7
  72. for %%d in (.d .D) do if "%%d"=="%8" goto d8
  73. for %%d in (.d .D) do if "%%d"=="%9" goto d9
  74. if "%2"==".nested" goto DelProcessed
  75. if "%2"==".d" goto DelProcessed
  76. %0 .rcx0 %0 %1 .n %2 %3 %4 %5 %6 %7 %8
  77. goto exit
  78.  
  79. :d2
  80. %0 .rcx0 %0 %1 .d %3 %4 %5 %6 %7 %8 %9
  81. goto exit
  82. :d3
  83. %0 .rcx0 %0 %1 .d %2 %4 %5 %6 %7 %8 %9
  84. goto exit
  85. :d4
  86. %0 .rcx0 %0 %1 .d %2 %3 %5 %6 %7 %8 %9
  87. goto exit
  88. :d5
  89. %0 .rcx0 %0 %1 .d %2 %3 %4 %6 %7 %8 %9
  90. goto exit
  91. :d6
  92. %0 .rcx0 %0 %1 .d %2 %3 %4 %5 %7 %8 %9
  93. goto exit
  94. :d7
  95. %0 .rcx0 %0 %1 .d %2 %3 %4 %5 %6 %8 %9
  96. goto exit
  97. :d8
  98. %0 .rcx0 %0 %1 .d %2 %3 %4 %5 %6 %7 %9
  99. goto exit
  100. :d9
  101. %0 .rcx0 %0 %1 .d %2 %3 %4 %5 %6 %7 %8
  102. goto exit
  103.  
  104. :DelProcessed
  105.  rem Suppress initial message with nested runs (recursive loops), specified by '.nested'
  106. if "%2"==".nested" goto begin1
  107.  
  108. echo RCX ReCursive .arc/.zipfile eXtractor by Jim Groeneveld, vs. 1.0, 29/1-93.
  109. echo ------------------------------------------------------------------------------
  110. echo Extracts one or more archives (.ARC/.ZIPfiles) into subdirectories named by
  111. echo the file_name part of the archive (or 'filename.DIR' if the archive has no
  112. echo extension itself) relative to the destination directory.
  113. echo ZIPfiles are extracted including their eventually stored directory structure.
  114. echo Nested archives (.ARC/.ZIPfiles) are recursively extracted into subdirectories
  115. echo named by the embedded .ARC/.ZIPfiles relative to the parent ARC/ZIPfile.
  116.  rem (DOS 2+)
  117. echo.
  118. if "%1"=="" goto helpRCX
  119. if "%2"=="" goto helpRCX
  120. if "%1"=="?" goto helpRCX
  121. if "%1"=="/?" goto helpRCX
  122. if "%1"=="-?" goto helpRCX
  123. if "%1"=="/h" goto helpRCX
  124. if "%1"=="/H" goto helpRCX
  125.  
  126. :begin1
  127. echo --- Check existence of target_path %1 ---
  128.  REM 'if not exist %1\nul goto no_target' REMOVE (replaced by 11 lines below)
  129. if exist %1\*.* goto begin2
  130.  rem If command above did not find anything the subdir might exist but be empty.
  131.  rem Avoid screen output if redirection below does not succeed: CTTY NUL.
  132.  rem ctty nul
  133.  rem write dummy file to the path %1 to check its existence
  134. rem>%1\$0-BYTE$.NUL
  135.  rem ctty con
  136. if not exist %1\$0-BYTE$.NUL goto no_target
  137.  rem The drive:path %1 does not exist (anymore).
  138.  rem Or the disk may be write protected.
  139. del %1\$0-BYTE$.NUL
  140.  
  141. :begin2
  142.  rem --- Process archive specifications %3 %4 %5 %6 %7 %8 %9 ---
  143.  rem ctty nul
  144.  rem for %%f in (%3..%9) do %0 .rcx1 %0 %1\ %2 %%f
  145.  rem CALL before FOR, because BAT2EXEC processes the set erroneously if
  146.  rem wildcards are involved.
  147.  rem (Split into separate lines for each part of set to prevent too long lines.)
  148. CALL for %%f in (%3) do %0 .rcx1 %0 %1\ %2 %%f
  149. CALL for %%f in (%4) do %0 .rcx1 %0 %1\ %2 %%f
  150. CALL for %%f in (%5) do %0 .rcx1 %0 %1\ %2 %%f
  151. CALL for %%f in (%6) do %0 .rcx1 %0 %1\ %2 %%f
  152. CALL for %%f in (%7) do %0 .rcx1 %0 %1\ %2 %%f
  153. CALL for %%f in (%8) do %0 .rcx1 %0 %1\ %2 %%f
  154. CALL for %%f in (%9) do %0 .rcx1 %0 %1\ %2 %%f
  155.  rem Try to add extensions .ARC and .ZIP to any file name (wildcard) if not nested:
  156. if "%2"==".nested" goto nested
  157. if exist %3.arc CALL for %%f in (%3.ARC) do %0 .rcx1 %0 %1\ %2 %%f
  158. if exist %4.arc CALL for %%f in (%4.ARC) do %0 .rcx1 %0 %1\ %2 %%f
  159. if exist %5.arc CALL for %%f in (%5.ARC) do %0 .rcx1 %0 %1\ %2 %%f
  160. if exist %6.arc CALL for %%f in (%6.ARC) do %0 .rcx1 %0 %1\ %2 %%f
  161. if exist %7.arc CALL for %%f in (%7.ARC) do %0 .rcx1 %0 %1\ %2 %%f
  162. if exist %8.arc CALL for %%f in (%8.ARC) do %0 .rcx1 %0 %1\ %2 %%f
  163. if exist %9.arc CALL for %%f in (%9.ARC) do %0 .rcx1 %0 %1\ %2 %%f
  164. if exist %3.zip CALL for %%f in (%3.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
  165. if exist %4.zip CALL for %%f in (%4.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
  166. if exist %5.zip CALL for %%f in (%5.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
  167. if exist %6.zip CALL for %%f in (%6.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
  168. if exist %7.zip CALL for %%f in (%7.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
  169. if exist %8.zip CALL for %%f in (%8.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
  170. if exist %9.zip CALL for %%f in (%9.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
  171.  rem (Lines above might be split into more shorter ones)
  172.  
  173. :nested
  174.  rem ctty con
  175. if "%2"==".nested" goto endRCX
  176.  rem Final termination of program, remove auxiliary batch file and report
  177. if exist $RCX$.BAT del $RCX$.BAT
  178. echo === RCX terminated normally; see log file RCX.LOG ===
  179. echo.>>rcx.log
  180. goto endRCX
  181.  
  182. :no_target
  183. echo --- Trying to create target_path %1 ---
  184. md %1
  185.  REM 'if exist %1\nul goto begin2' REMOVE (replaced by about 10 lines below)
  186.  rem Avoid screen output if redirection below does not succeed: CTTY NUL.
  187.  rem ctty nul
  188.  rem write dummy file to the path %1 to check its existence
  189. rem>%1\$0-BYTE$.NUL
  190.  rem ctty con
  191. if exist %1\$0-BYTE$.NUL goto Delete_1
  192. echo *** Target path %1 does not exist and cannot be created. ABORT.
  193. echo *** Target path %1 does not exist and cannot be created. ABORT.>>rcx.log
  194. goto nested
  195.  
  196. :Delete_1
  197.  rem Delete dummy check file
  198. del %1\$0-BYTE$.NUL
  199. goto begin2
  200.  
  201. :helpRCX
  202. echo Syntax: RCX «target_path» «source_path_file» [«source_path_file» [..]] [.d]
  203. echo in which
  204. echo «target_path»      = [d:]path of destination (drive/)directory, or relative
  205. echo                                 to current ('.') one, excl. trailing '\'!
  206. REM -------- (REDUNDANT) ---------   Specify root '\' eventually as '\.'.
  207. echo «source_path_file» = [d:][path\]filename of ARC/ZIPfile(s) to extract (up to 7)
  208. echo                                 (wildcards allowed; extensions redundant)
  209. echo                                 Avoid files with the same file name part and
  210. echo                                 different archive ext's (.ARC and .ZIP).
  211. echo .d                 = parameter indicating deletion of original archive
  212. echo                                 (.ARC/.ZIP) after extraction.
  213. echo                      Embedded ARC/ZIPfiles always are automatically deleted.
  214. :endRCX
  215. goto exit
  216.  
  217. :_RCX_1
  218. shift
  219. shift
  220.  rem _RCX_1 receives (1) target_path, (2) deletion option (.d or .n or .nested)
  221.  rem and (3) single file specification
  222.  rem If parameter (4) exists it is the already discriminated filename part
  223.  rem If parameter (5) exists it is the already discriminated extension or 'none'
  224.  rem In fact %3 is never expected to be empty, but though:
  225. if "%3"=="" goto endRCX_1
  226.  REM *** for %%f in (.d .D .nested .d.arc .D.arc .d.zip .D.zip) do if "%2"=="%%f" goto endRCX_1
  227.  rem %3 may not exist if a single file name (no wildcard) was specified
  228. if not "%4"=="" goto make_sub
  229. if not exist %3 goto not_exist
  230.    rem create subdirectory from single file specification:
  231.    rem Uility GETFNX discriminates a.o. the filename
  232.   echo --- Search for filename part in %3 ---
  233.   GETFNX %3
  234.   if not exist GETFNX2.BAT goto nogetfnx
  235.    rem Call GETFNX2 and restart %0 recursively via the auxiliary batch file
  236.    rem $RCX$.BAT in order not to have (a former copy of) GETFNX2 running
  237.    rem while it will be rewritten during nesting.
  238.   GETFNX2 $RCX$ %0 .rcx1 %0 %1 %2 %3
  239.   goto exit
  240.    rem -------------- loopback
  241.  
  242. :nogetfnx
  243. echo *** Directory name can not be determined. Leave archive in place.
  244.  rem (or some other solution: issuing standard directory names)
  245. goto exit
  246.  
  247. :make_sub
  248.  rem If no extension was specified with the source file make the subdirectory name,
  249.  rem in which to extract, equal to the file name and the extension 'DIR' and
  250.  rem add a dot after the original file name in order to avoid PKUNPAK and PKUNZIP
  251.  rem to assume their implicit extension .ARC or .ZIP:
  252. if not "%5"=="none" goto NotNone
  253.   %0 .rcx1 %0 %1 %2 %3. %4.DIR NONE
  254.   goto exit
  255. :NotNone
  256.  rem Second loop: delete scratch file GETFNX2.BAT, used in first loop
  257. if exist GETFNX2.BAT del GETFNX2.BAT
  258.  rem make subdirectory (and test for success); first test for existence
  259.  REM 'if exist %1%4\nul goto extract' REMOVE (replaced by 14 lines below)
  260. if exist %1%4\*.* goto extract
  261.  rem If command above did not find anything the subdir might exist but be empty.
  262.  rem Avoid screen output if redirection below does not succeed: CTTY NUL.
  263.  rem ctty nul
  264.  rem write dummy file to the path %1%4 to check its existence
  265. rem>%1%4\$0-BYTE$.NUL
  266.  rem ctty con
  267. if exist %1%4\$0-BYTE$.NUL goto Delete_2
  268.  rem The drive:path %1%4 does not exist.
  269. goto create
  270.  
  271. :Delete_2
  272.  rem Delete dummy check file
  273. del %1%4\$0-BYTE$.NUL
  274. goto extract
  275.  
  276. :create
  277. echo --- Trying to create subdirectory %1%4 ---
  278. md %1%4
  279.  REM 'if exist %1%4\nul goto extract' REMOVE (replaced by 14 lines below)
  280. if exist %1%4\*.* goto extract
  281.  rem If command above did not find anything the subdir might exist but be empty.
  282.  rem Avoid screen output if redirection below does not succeed: CTTY NUL.
  283.  rem ctty nul
  284.  rem write dummy file to the path %1%4 to check its existence
  285. rem>%1%4\$0-BYTE$.NUL
  286.  rem ctty con
  287. if exist %1%4\$0-BYTE$.NUL goto Delete_2
  288.  rem The drive:path %1%4 does not exist.
  289. echo *** Subdirectory %1%4 could not be created, archive %3 not extracted and deleted.
  290. echo *** Subdirectory %1%4 could not be created, archive %3 not extracted and deleted.>>rcx.log
  291. goto endRCX_1
  292.  
  293. :not_exist
  294. echo *** File %3 does not exist, no action.
  295. echo *** File %3 does not exist, no action.>>rcx.log
  296. goto endRCX_1
  297.  
  298. :extract
  299. echo --- Extract archive %3 into subdirectory %1%4 ---
  300. for %%a in (arc ARC) do if "%5"=="%%a" goto arc_direct
  301.  rem Avoid files with the same file name part and different archive ext's (.ARC and .ZIP).
  302. pkunzip -d -JHSR %3 %1%4
  303. if not errorlevel 1 goto del_archive
  304.  
  305. :arc_direct
  306. pkunpak -x %3 %1%4
  307. if not errorlevel 1 goto del_archive
  308.  rem Errorlevel is at least 1
  309. echo *** An error occurred while extracting archive %3, not deleted!
  310. echo *** An error occurred while extracting archive %3, not deleted!>>rcx.log
  311. goto restart
  312.  
  313. :del_archive
  314. echo !!! Archive %3 extracted successfully>>rcx.log
  315. if "%2"==".n" goto restart
  316.  rem else %2 is either '.d' or '.nested' indicating deletion
  317. echo Auto-deletion of %3
  318. del %3
  319. if exist %3 goto not_deleted
  320. echo !!! Archive %3 deleted>>rcx.log
  321. goto restart
  322.  
  323. :not_deleted
  324. echo *** Archive %3 could not be deleted automatically.
  325. echo *** Archive %3 could not be deleted automatically.>>rcx.log
  326.  
  327. :restart
  328.  rem Restart RCX specifying target_SUBdirectory as both (relative) target and source recursively
  329. echo --- Process eventual archives (ARC/ZIPfiles) in %1%4 ---
  330.  rem ctty nul
  331. %0 .rcx0 %0 %1%4 .nested %1%4\*.ARC %1%4\*.ZIP
  332.  rem ctty con
  333. :endRCX_1
  334.  rem goto exit
  335.  
  336. :exit
  337.