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 >
Wrap
Text File
|
1993-01-29
|
13KB
|
337 lines
@echo off
rem The DOS internal CTTY command does not seem to be effective if compiled.
rem ctty con
for %%N in (0 1) do if "%1"==".rcx%%N" goto _RCX_%%N
rem if "%1"==".rcx0" goto _RCX_0 ──┤
rem if "%1"==".rcx1" goto _RCX_1 ──┘
if "%1"==".aux" goto CreateAux
if "%1"=="" goto no_log
if "%2"=="" goto no_log
rem Open/append log file RCX.LOG during the first initial run only:
if exist rcx.log goto AppendLog
rem Compiled program can not append to non-existing output, so create it now:
rem>rcx.log
:AppendLog
echo ========================== RCX.LOG ==========================>>rcx.log
echo.|date|find "is">>rcx.log
echo.|time|find "is">>rcx.log
echo COMMAND LINE: %0 %1 %2 %3 %4 %5 %6 %7 %8 %9>>rcx.log
rem Creation of auxiliary file in separate shelled run, because otherwise
rem IF COMPILED WITH BAT2EXEC vs. 1.5 THIS PROGRAM SUFFERS FROM A SEVERE BUG
rem THAT DEMONSTRATES ITSELF BY TRYING TO WRITE TO THE STANDARD PRINTER PORT.
rem SO COMPILING THIS PROGRAM IS NOT RECOMMENDED! YET THIS SOURCE HAS BEEN
rem INCLUDED FOR COMPILING WITH OTHER OR NEWER BATCH FILE COMPILERS.
%0 .aux
:no_log
goto _RCX
:CreateAux
rem Create auxiliary file $RCX$.BAT in current directory to use during the
rem recursive process, because otherwise each nested level would want its own,
rem yet active copy of the batch file GETFNX2, generated by GETFNX, while that
rem one is being rewritten during nesting for each potential file to extract.
rem The GETFNX2 batch file passes control to this auxiliary file (that remains
rem unchanged, and still may be active for many levels at the same time) and
rem thus may be rewritten as often as desired. This auxiliary file should be
rem removed at the end of the program.
echo echo off>$RCX$.BAT
echo shift>>$RCX$.BAT
echo %%0 %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>>$RCX$.BAT
goto exit
:_RCX_0
shift
shift
:_RCX
rem Change root '\' as target dir into '\.' for correct further processing
if "%1"=="\" goto is_root
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
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
goto continue
:is_root
%0 .rcx0 %0 %1. %2 %3 %4 %5 %6 %7 %8 %9
goto exit
:continue
rem ....................... process DELETE parameter ........................
if "%1"=="" goto DelProcessed
if "%2"=="" goto DelProcessed
rem If parameter .d or .D is specified somewhere, make it the second one '.d'
rem If it has not been specified make the second parameter '.n' of not '.nested'
if "%2"==".n" goto DelProcessed
for %%d in ( .D) do if "%%d"=="%2" goto d2
for %%d in (.d .D) do if "%%d"=="%3" goto d3
for %%d in (.d .D) do if "%%d"=="%4" goto d4
for %%d in (.d .D) do if "%%d"=="%5" goto d5
for %%d in (.d .D) do if "%%d"=="%6" goto d6
for %%d in (.d .D) do if "%%d"=="%7" goto d7
for %%d in (.d .D) do if "%%d"=="%8" goto d8
for %%d in (.d .D) do if "%%d"=="%9" goto d9
if "%2"==".nested" goto DelProcessed
if "%2"==".d" goto DelProcessed
%0 .rcx0 %0 %1 .n %2 %3 %4 %5 %6 %7 %8
goto exit
:d2
%0 .rcx0 %0 %1 .d %3 %4 %5 %6 %7 %8 %9
goto exit
:d3
%0 .rcx0 %0 %1 .d %2 %4 %5 %6 %7 %8 %9
goto exit
:d4
%0 .rcx0 %0 %1 .d %2 %3 %5 %6 %7 %8 %9
goto exit
:d5
%0 .rcx0 %0 %1 .d %2 %3 %4 %6 %7 %8 %9
goto exit
:d6
%0 .rcx0 %0 %1 .d %2 %3 %4 %5 %7 %8 %9
goto exit
:d7
%0 .rcx0 %0 %1 .d %2 %3 %4 %5 %6 %8 %9
goto exit
:d8
%0 .rcx0 %0 %1 .d %2 %3 %4 %5 %6 %7 %9
goto exit
:d9
%0 .rcx0 %0 %1 .d %2 %3 %4 %5 %6 %7 %8
goto exit
:DelProcessed
rem Suppress initial message with nested runs (recursive loops), specified by '.nested'
if "%2"==".nested" goto begin1
echo RCX ReCursive .arc/.zipfile eXtractor by Jim Groeneveld, vs. 1.0, 29/1-93.
echo ------------------------------------------------------------------------------
echo Extracts one or more archives (.ARC/.ZIPfiles) into subdirectories named by
echo the file_name part of the archive (or 'filename.DIR' if the archive has no
echo extension itself) relative to the destination directory.
echo ZIPfiles are extracted including their eventually stored directory structure.
echo Nested archives (.ARC/.ZIPfiles) are recursively extracted into subdirectories
echo named by the embedded .ARC/.ZIPfiles relative to the parent ARC/ZIPfile.
rem (DOS 2+)
echo.
if "%1"=="" goto helpRCX
if "%2"=="" goto helpRCX
if "%1"=="?" goto helpRCX
if "%1"=="/?" goto helpRCX
if "%1"=="-?" goto helpRCX
if "%1"=="/h" goto helpRCX
if "%1"=="/H" goto helpRCX
:begin1
echo --- Check existence of target_path %1 ---
REM 'if not exist %1\nul goto no_target' REMOVE (replaced by 11 lines below)
if exist %1\*.* goto begin2
rem If command above did not find anything the subdir might exist but be empty.
rem Avoid screen output if redirection below does not succeed: CTTY NUL.
rem ctty nul
rem write dummy file to the path %1 to check its existence
rem>%1\$0-BYTE$.NUL
rem ctty con
if not exist %1\$0-BYTE$.NUL goto no_target
rem The drive:path %1 does not exist (anymore).
rem Or the disk may be write protected.
del %1\$0-BYTE$.NUL
:begin2
rem --- Process archive specifications %3 %4 %5 %6 %7 %8 %9 ---
rem ctty nul
rem for %%f in (%3..%9) do %0 .rcx1 %0 %1\ %2 %%f
rem CALL before FOR, because BAT2EXEC processes the set erroneously if
rem wildcards are involved.
rem (Split into separate lines for each part of set to prevent too long lines.)
CALL for %%f in (%3) do %0 .rcx1 %0 %1\ %2 %%f
CALL for %%f in (%4) do %0 .rcx1 %0 %1\ %2 %%f
CALL for %%f in (%5) do %0 .rcx1 %0 %1\ %2 %%f
CALL for %%f in (%6) do %0 .rcx1 %0 %1\ %2 %%f
CALL for %%f in (%7) do %0 .rcx1 %0 %1\ %2 %%f
CALL for %%f in (%8) do %0 .rcx1 %0 %1\ %2 %%f
CALL for %%f in (%9) do %0 .rcx1 %0 %1\ %2 %%f
rem Try to add extensions .ARC and .ZIP to any file name (wildcard) if not nested:
if "%2"==".nested" goto nested
if exist %3.arc CALL for %%f in (%3.ARC) do %0 .rcx1 %0 %1\ %2 %%f
if exist %4.arc CALL for %%f in (%4.ARC) do %0 .rcx1 %0 %1\ %2 %%f
if exist %5.arc CALL for %%f in (%5.ARC) do %0 .rcx1 %0 %1\ %2 %%f
if exist %6.arc CALL for %%f in (%6.ARC) do %0 .rcx1 %0 %1\ %2 %%f
if exist %7.arc CALL for %%f in (%7.ARC) do %0 .rcx1 %0 %1\ %2 %%f
if exist %8.arc CALL for %%f in (%8.ARC) do %0 .rcx1 %0 %1\ %2 %%f
if exist %9.arc CALL for %%f in (%9.ARC) do %0 .rcx1 %0 %1\ %2 %%f
if exist %3.zip CALL for %%f in (%3.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
if exist %4.zip CALL for %%f in (%4.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
if exist %5.zip CALL for %%f in (%5.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
if exist %6.zip CALL for %%f in (%6.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
if exist %7.zip CALL for %%f in (%7.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
if exist %8.zip CALL for %%f in (%8.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
if exist %9.zip CALL for %%f in (%9.ZIP) do %0 .rcx1 %0 %1\ %2 %%f
rem (Lines above might be split into more shorter ones)
:nested
rem ctty con
if "%2"==".nested" goto endRCX
rem Final termination of program, remove auxiliary batch file and report
if exist $RCX$.BAT del $RCX$.BAT
echo === RCX terminated normally; see log file RCX.LOG ===
echo.>>rcx.log
goto endRCX
:no_target
echo --- Trying to create target_path %1 ---
md %1
REM 'if exist %1\nul goto begin2' REMOVE (replaced by about 10 lines below)
rem Avoid screen output if redirection below does not succeed: CTTY NUL.
rem ctty nul
rem write dummy file to the path %1 to check its existence
rem>%1\$0-BYTE$.NUL
rem ctty con
if exist %1\$0-BYTE$.NUL goto Delete_1
echo *** Target path %1 does not exist and cannot be created. ABORT.
echo *** Target path %1 does not exist and cannot be created. ABORT.>>rcx.log
goto nested
:Delete_1
rem Delete dummy check file
del %1\$0-BYTE$.NUL
goto begin2
:helpRCX
echo Syntax: RCX «target_path» «source_path_file» [«source_path_file» [..]] [.d]
echo in which
echo «target_path» = [d:]path of destination (drive/)directory, or relative
echo to current ('.') one, excl. trailing '\'!
REM -------- (REDUNDANT) --------- Specify root '\' eventually as '\.'.
echo «source_path_file» = [d:][path\]filename of ARC/ZIPfile(s) to extract (up to 7)
echo (wildcards allowed; extensions redundant)
echo Avoid files with the same file name part and
echo different archive ext's (.ARC and .ZIP).
echo .d = parameter indicating deletion of original archive
echo (.ARC/.ZIP) after extraction.
echo Embedded ARC/ZIPfiles always are automatically deleted.
:endRCX
goto exit
:_RCX_1
shift
shift
rem _RCX_1 receives (1) target_path, (2) deletion option (.d or .n or .nested)
rem and (3) single file specification
rem If parameter (4) exists it is the already discriminated filename part
rem If parameter (5) exists it is the already discriminated extension or 'none'
rem In fact %3 is never expected to be empty, but though:
if "%3"=="" goto endRCX_1
REM *** for %%f in (.d .D .nested .d.arc .D.arc .d.zip .D.zip) do if "%2"=="%%f" goto endRCX_1
rem %3 may not exist if a single file name (no wildcard) was specified
if not "%4"=="" goto make_sub
if not exist %3 goto not_exist
rem create subdirectory from single file specification:
rem Uility GETFNX discriminates a.o. the filename
echo --- Search for filename part in %3 ---
GETFNX %3
if not exist GETFNX2.BAT goto nogetfnx
rem Call GETFNX2 and restart %0 recursively via the auxiliary batch file
rem $RCX$.BAT in order not to have (a former copy of) GETFNX2 running
rem while it will be rewritten during nesting.
GETFNX2 $RCX$ %0 .rcx1 %0 %1 %2 %3
goto exit
rem -------------- loopback
:nogetfnx
echo *** Directory name can not be determined. Leave archive in place.
rem (or some other solution: issuing standard directory names)
goto exit
:make_sub
rem If no extension was specified with the source file make the subdirectory name,
rem in which to extract, equal to the file name and the extension 'DIR' and
rem add a dot after the original file name in order to avoid PKUNPAK and PKUNZIP
rem to assume their implicit extension .ARC or .ZIP:
if not "%5"=="none" goto NotNone
%0 .rcx1 %0 %1 %2 %3. %4.DIR NONE
goto exit
:NotNone
rem Second loop: delete scratch file GETFNX2.BAT, used in first loop
if exist GETFNX2.BAT del GETFNX2.BAT
rem make subdirectory (and test for success); first test for existence
REM 'if exist %1%4\nul goto extract' REMOVE (replaced by 14 lines below)
if exist %1%4\*.* goto extract
rem If command above did not find anything the subdir might exist but be empty.
rem Avoid screen output if redirection below does not succeed: CTTY NUL.
rem ctty nul
rem write dummy file to the path %1%4 to check its existence
rem>%1%4\$0-BYTE$.NUL
rem ctty con
if exist %1%4\$0-BYTE$.NUL goto Delete_2
rem The drive:path %1%4 does not exist.
goto create
:Delete_2
rem Delete dummy check file
del %1%4\$0-BYTE$.NUL
goto extract
:create
echo --- Trying to create subdirectory %1%4 ---
md %1%4
REM 'if exist %1%4\nul goto extract' REMOVE (replaced by 14 lines below)
if exist %1%4\*.* goto extract
rem If command above did not find anything the subdir might exist but be empty.
rem Avoid screen output if redirection below does not succeed: CTTY NUL.
rem ctty nul
rem write dummy file to the path %1%4 to check its existence
rem>%1%4\$0-BYTE$.NUL
rem ctty con
if exist %1%4\$0-BYTE$.NUL goto Delete_2
rem The drive:path %1%4 does not exist.
echo *** Subdirectory %1%4 could not be created, archive %3 not extracted and deleted.
echo *** Subdirectory %1%4 could not be created, archive %3 not extracted and deleted.>>rcx.log
goto endRCX_1
:not_exist
echo *** File %3 does not exist, no action.
echo *** File %3 does not exist, no action.>>rcx.log
goto endRCX_1
:extract
echo --- Extract archive %3 into subdirectory %1%4 ---
for %%a in (arc ARC) do if "%5"=="%%a" goto arc_direct
rem Avoid files with the same file name part and different archive ext's (.ARC and .ZIP).
pkunzip -d -JHSR %3 %1%4
if not errorlevel 1 goto del_archive
:arc_direct
pkunpak -x %3 %1%4
if not errorlevel 1 goto del_archive
rem Errorlevel is at least 1
echo *** An error occurred while extracting archive %3, not deleted!
echo *** An error occurred while extracting archive %3, not deleted!>>rcx.log
goto restart
:del_archive
echo !!! Archive %3 extracted successfully>>rcx.log
if "%2"==".n" goto restart
rem else %2 is either '.d' or '.nested' indicating deletion
echo Auto-deletion of %3
del %3
if exist %3 goto not_deleted
echo !!! Archive %3 deleted>>rcx.log
goto restart
:not_deleted
echo *** Archive %3 could not be deleted automatically.
echo *** Archive %3 could not be deleted automatically.>>rcx.log
:restart
rem Restart RCX specifying target_SUBdirectory as both (relative) target and source recursively
echo --- Process eventual archives (ARC/ZIPfiles) in %1%4 ---
rem ctty nul
%0 .rcx0 %0 %1%4 .nested %1%4\*.ARC %1%4\*.ZIP
rem ctty con
:endRCX_1
rem goto exit
:exit