home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
r
/
rcx10.zip
/
GETFNX10.ZIP
/
GETFNX.B2C
< prev
next >
Wrap
Text File
|
1993-01-29
|
9KB
|
231 lines
@echo off
rem The DOS internal CTTY command does not seem to be effective if compiled.
rem ctty con
if "%1"==".path" goto Path
if "%2"==".NotFound" goto NoPath
if "%1"==".getfnx2" goto GETFNX_2
rem delete currently existing scratch file _GETFNX1.BAT to be generated:
if exist _GETFNX1.BAT del _GETFNX1.BAT
rem delete currently existing batch file GETFNX2.BAT to be generated and called by application:
if exist GETFNX2.BAT del GETFNX2.BAT
if "%1"=="" goto Help
if "%1"=="?" goto Help
if "%1"=="/?" goto Help
if "%1"=="-?" goto Help
if "%1"=="/h" goto Help
if "%1"=="/H" goto Help
if not exist %1 goto NotExist
if not "%2"=="" goto GETFNX_1
rem %2 is the location or specification of the auxiliary file $GETFNX$.AUX
:Determine
rem Determination of location (and name) of auxiliary file $GETFNX$.AUX in/as:
rem a. the second parameter when calling GETFNX (not checked here)
rem 1. the full _path_ only, incl. trailing '\' (e.g. 'GETFNX filename.ext C:\UTIL\') or
rem 2. the full _file_specification_ (e.g. 'GETFNX filename.ext C:\UTIL\AUX-FILE.$$$')
rem b. the environment variable %GETFNX%
rem 1. the full _path_ only, incl. trailing '\' ('SET GETFNX=C:\UTIL\') or
rem 2. the full _file_specification_ ('SET GETFNX=C:\UTIL\AUX-FILE.$$$')
rem c. the ROOT directory of C: (C:\) (or automatically any APPENDed path) or
rem d. the ROOT directory of the CURRENT drive (\) or
rem e. the CURRENT directory (.\) or
rem f. the PARENT directory of the current one (..\) or
rem g. the SAME directory where GETFNX.COM/.EXE is residing
rem (compiled %0 includes the whole path to the program) or
rem h. the DOS PATH variable (this may take quite a while)
rem If the environment variable has not been set: try other location(s)
if "%GETFNX%"=="" goto NoEnvVar
rem If $GETFNX$.AUX found as file specified by %GETFNX% then restart this batch
rem file (GETFNX.COM/.EXE as %0) with _full_path_&_file_name_ as the second parameter
if not exist %GETFNX% goto NoAuxFileVar
%0 %1 %GETFNX%
goto exit
:NoAuxFileVar
rem If $GETFNX$.AUX found in path specified by %GETFNX% then restart this batch
rem file (GETFNX.COM/.EXE as %0) with _full_path_&_file_name_ as the second parameter
if not exist %GETFNX%$GETFNX$.AUX goto NoAuxPathVar
%0 %1 %GETFNX%$GETFNX$.AUX
goto exit
:NoAuxPathVar
rem If the auxiliary file thus can not be found: try other location(s) below:
:NoEnvVar
rem Check the presence of $GETFNX$.AUX in (and specify _full_path_&_file_name_
rem if found):
rem (the root of C:)
if not exist C:\$GETFNX$.AUX goto NoCRoot
%0 %1 C:\$GETFNX$.AUX
goto exit
:NoCRoot
rem (the root of the current drive)
if not exist \$GETFNX$.AUX goto NoCurRoot
%0 %1 \$GETFNX$.AUX
goto exit
:NoCurRoot
rem (the current directory)
if not exist .\$GETFNX$.AUX goto NoCurrent
%0 %1 .\$GETFNX$.AUX
goto exit
:NoCurrent
rem (the parent directory)
if not exist ..\$GETFNX$.AUX goto NoParent
%0 %1 ..\$GETFNX$.AUX
goto exit
:NoParent
rem (the directory in which GETFNX.COM is situated)
if not exist %0\..\$GETFNX$.AUX goto DOSPATH
%0 %1 %0\..\$GETFNX$.AUX
goto exit
:DOSPATH
rem ---DOSPATH---
rem Within the subroutine :Path to be called now by subsequent 'shift'ing
rem the call name for GETFNX (%0) as well as the first argument (%1),
rem specifying the filename.ext to be split, gets lost. To solve this
rem problem a temporary batch file $GETFNX$.BAT is created initially (in
rem the current directory) that contains this information hardcoded and
rem calls GETFNX (or whatever it is renamed) with the necessary parameter:
echo echo off>$GETFNX$.BAT
rem If no write of this auxiliary file is possible then cancel finally:
if not exist $GETFNX$.BAT goto NoPath
echo %0 %1 %%1>>$GETFNX$.BAT
rem At the end (or somewhere suited) remove the temporary file $GETFNX$.BAT .
rem Depending on the (path and) name (length) for GETFNX the path environment
rem variable will be used up to a certain number of characters, maximally
rem around 100.
%0 .path %path%
rem delete auxiliary file $GETFNX$.BAT after use by finding DOS PATH
del $GETFNX$.BAT
goto exit
:NoPath
echo *** Necessary auxilary file $GETFNX$.AUX could not be found - abort!
echo.
echo Specify environment variable GETFNX to point to the path where
echo $GETFNX$.AUX resides (either from the DOS prompt or in AUTOEXEC.BAT).
echo E.g. SET GETFNX=C:\UTIL\ (terminated with backslash).
echo Or specify full path and file name to the eventual alternate auxiliary
echo file for $GETFNX$.AUX (e.g. SET GETFNX=C:\UTIL\AUX-FILE.$$$).
echo.
echo Or specify path (terminated with '\') to or full file specification
echo for $GETFNX$.AUX as the second parameter for %0
goto end
:GETFNX_1
rem If %2 is _full_path_&_file_name_ of (alternate) $GETFNX$.AUX then continue
if exist %2 goto AuxPathChecked
rem If %2 is path only to explicit $GETFNX$.AUX then restart GETFNX (%0) with
rem _full_path_&_file_name_ as the first parameter
if not exist %2$GETFNX$.AUX goto NoAuxSpec
%0 %1 %2$GETFNX$.AUX
goto exit
:NoAuxSpec
rem %2 has been specified by the user, but $GETFNX$.AUX could not be found:
echo *** Auxiliary path[file] %2 is incorrect, file $GETFNX$.AUX not found.
echo Now trying to find $GETFNX$.AUX using path (or full file specification):
echo 1. from environment variable GETFNX (path or full file specification)
echo 2. the root directory of C: (C:\) (or automatically any APPENDed path)
echo 3. the root of the current drive (\)
echo 4. the current directory (.\)
echo 5. the parent directory (..\)
echo 6. the same directory as GETFNX.COM/.EXE
echo 7. from the DOS PATH variable (this may take quite a while)
echo.
goto Determine
:AuxPathChecked
echo --- Extract filename and extension from %1 ---
echo echo off>_getfnx1.bat
if not exist _getfnx1.bat goto Impossible
rem ctty nul
copy _getfnx1.bat+%2 /a _getfnx1.bat /b>nul
rem Next lines twice with slight difference in order to "dir" a file name without an extension correctly.
if not exist %1. goto HasExt
dir/w %1.|find " ">>_getfnx1.bat
goto NoExt
:HasExt
dir/w %1 |find " ">>_getfnx1.bat
:NoExt
_getfnx1 %0 .getfnx2 %0
del _GETFNX1.BAT
rem ctty con
echo --- Extracted parts written to GETFNX2.BAT for further use ---
goto end
:NotExist
echo Specified file %1 does not exist. ABORT.
goto end
:Impossible
echo *** Temporary batch file for further processing could not be created. Abort!
goto end
:Help
echo GETFNX File name - extension splitter by Jim Groeneveld, vs. 1.0, 29/1-93.
echo.
echo Syntax: GETFNX [d:][\][path\]filename.ext [[d:][\][path\][auxfilespec]]
echo where d: = drive: (of concerning file);
echo path = absolute or relative path ([\]sub1\sub2.....\);
echo filename.ext = file specification to split into name and extension;
echo auxfilespec = the eventual alt. auxiliary file name for $GETFNX$.AUX;
echo.
echo Output: batch file GETFNX2.BAT with contents:
echo echo off
echo %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 filename extension
echo (extension may be 'none')
echo to be called by application using:
echo call GETFNX2 ownbatch [par1..par7] fn ext
echo User's batch file 'ownbatch.bat' may do anything with these parameters.
:end
goto exit
:GETFNX_2
shift
shift
if not "%2"=="" goto Create2
%0 .getfnx2 %0 %1 none
goto exit
:Create2
echo echo off>GETFNX2.BAT
echo %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %1 %2>>GETFNX2.BAT
goto exit
:Path SUBROUTINE PATH
shift
:ChkPath
rem Check each path entry for the presence of $GETFNX$.AUX:
if "%1"=="" goto NotFound
rem Check root specifications (ending with a trailing \) firstly: *
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 "%%a:\"=="%1" goto RootPath *
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 "%%a:\"=="%1" goto RootPath *
rem Path spec is not a root *
rem If $RETURN.AUX has been found then restart with location as parameter
if not exist %1\$GETFNX$.AUX goto NoSubDirPath
$GETFNX$ %1\$GETFNX$.AUX
goto exit
:NoSubDirPath
goto NextPath *
:RootPath *
rem If $RETURN.AUX has been found then restart with location as parameter *
if not exist %1$GETFNX$.AUX goto NoRootPath
$GETFNX$ %1$GETFNX$.AUX
goto exit
:NoRootPath
rem goto NextPath *
:NextPath *
rem Check next path entry:
shift
goto ChkPath
:NotFound
rem path or auxiliary file not found, indicate
$GETFNX$ .NotFound
rem Lines marked with * may eventually be deleted all at once resulting in a
rem slightly changed check algorithm: 1. _with_ '\' and 2. _without_ '\'.
rem These lines should work, however, with the * included.
rem goto exit
:exit