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.BAT < prev    next >
DOS Batch File  |  1993-01-29  |  9KB  |  199 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. if "%1"==".path" goto Path
  6. if "%2"==".NotFound" goto NoPath
  7. if "%1"==".getfnx2" goto GETFNX_2
  8.  rem delete currently existing scratch file _GETFNX1.BAT to be generated:
  9. if exist _GETFNX1.BAT del _GETFNX1.BAT
  10.  rem delete currently existing batch file GETFNX2.BAT to be generated and called by application:
  11. if exist GETFNX2.BAT del GETFNX2.BAT
  12. if "%1"=="" goto Help
  13. if "%1"=="?" goto Help
  14. if "%1"=="/?" goto Help
  15. if "%1"=="-?" goto Help
  16. if "%1"=="/h" goto Help
  17. if "%1"=="/H" goto Help
  18. if not exist %1 goto NotExist
  19. if not "%2"=="" goto GETFNX_1
  20.   rem %2 is the location or specification of the auxiliary file $GETFNX$.AUX
  21.  
  22. :Determine
  23.  rem Determination of location (and name) of auxiliary file $GETFNX$.AUX in/as:
  24.  rem a. the second parameter when calling GETFNX (not checked here)
  25.  rem    1. the full _path_ only, incl. trailing '\' (e.g. 'GETFNX filename.ext C:\UTIL\') or
  26.  rem    2. the full _file_specification_ (e.g. 'GETFNX filename.ext C:\UTIL\AUX-FILE.$$$')
  27.  rem b. the environment variable %GETFNX%
  28.  rem    1. the full _path_ only, incl. trailing '\' ('SET GETFNX=C:\UTIL\') or
  29.  rem    2. the full _file_specification_ ('SET GETFNX=C:\UTIL\AUX-FILE.$$$')
  30.  rem c. the ROOT directory of C: (C:\) (or automatically any APPENDed path) or
  31.  rem d. the ROOT directory of the CURRENT drive (\) or
  32.  rem e. the CURRENT directory (.\) or
  33.  rem f. the PARENT directory of the current one (..\) or
  34.  rem g. the SAME directory where GETFNX.BAT is residing:
  35.  rem    if EXPLICITELY specified when starting GETFNX (DOS 3.x&up only).
  36.  rem    (NOT if GETFNX.BAT can only be found via the PATH!) or
  37.  rem h. the DOS PATH variable (this may take quite a while)
  38.  rem If the environment variable has not been set: try other location(s)
  39. if "%GETFNX%"=="" goto NoEnvVar
  40.  rem If $GETFNX$.AUX found as file specified by %GETFNX% then restart this batch
  41.  rem file (GETFNX.BAT as %0) with _full_path_&_file_name_ as the second parameter
  42. if exist %GETFNX% %0 %1 %GETFNX%
  43.  rem If $GETFNX$.AUX found in path specified by %GETFNX% then restart this batch
  44.  rem file (GETFNX.BAT as %0) with _full_path_&_file_name_ as the second parameter
  45. if exist %GETFNX%$GETFNX$.AUX %0 %1 %GETFNX%$GETFNX$.AUX
  46.  rem If the auxiliary file thus can not be found: try other location(s) below:
  47.  
  48. :NoEnvVar
  49.  rem Check the presence of $GETFNX$.AUX in (and specify _full_path_&_file_name_
  50.  rem if found):
  51.  rem (the root of C:)
  52. if exist    C:\$GETFNX$.AUX %0 %1    C:\$GETFNX$.AUX
  53.  rem (the root of the current drive)
  54. if exist      \$GETFNX$.AUX %0 %1      \$GETFNX$.AUX
  55.  rem (the current directory)
  56. if exist     .\$GETFNX$.AUX %0 %1     .\$GETFNX$.AUX
  57.  rem (the parent directory)
  58. if exist    ..\$GETFNX$.AUX %0 %1    ..\$GETFNX$.AUX
  59.  rem (the explicitely specified directory)
  60. if exist %0\..\$GETFNX$.AUX %0 %1 %0\..\$GETFNX$.AUX
  61.  
  62.  rem ---DOSPATH---
  63.  rem Within the subroutine :Path to be called now by subsequent 'shift'ing
  64.  rem the call name for GETFNX (%0) as well as the first argument (%1),
  65.  rem specifying the filename.ext to be split, gets lost. To solve this
  66.  rem problem a temporary batch file $GETFNX$.BAT is created initially (in
  67.  rem the current directory) that contains this information hardcoded and
  68.  rem calls GETFNX (or whatever it is renamed) with the necessary parameter:
  69. echo echo off>$GETFNX$.BAT
  70.  rem If no write of this auxiliary file is possible then cancel finally:
  71. if not exist $GETFNX$.BAT goto NoPath
  72. echo %0 %1 %%1>>$GETFNX$.BAT
  73.  rem At the end (or somewhere suited) remove the temporary file $GETFNX$.BAT .
  74.  rem Depending on the (path and) name (length) for GETFNX the path environment
  75.  rem variable will be used up to a certain number of characters, maximally
  76.  rem around 100.
  77. %0 .path %path%
  78.  
  79. :NoPath
  80. echo *** Necessary auxilary file $GETFNX$.AUX could not be found - abort!
  81. echo.
  82. echo     Specify environment variable GETFNX to point to the path where
  83. echo     $GETFNX$.AUX resides (either from the DOS prompt or in AUTOEXEC.BAT).
  84. echo     E.g. SET GETFNX=C:\UTIL\             (terminated with backslash).
  85. echo     Or specify full path and file name to the eventual alternate auxiliary
  86. echo     file for $GETFNX$.AUX (e.g. SET GETFNX=C:\UTIL\AUX-FILE.$$$).
  87. echo.
  88. echo     Or specify path (terminated with '\') to or full file specification
  89. echo     for $GETFNX$.AUX as the second parameter for %0
  90. goto end
  91.  
  92. :GETFNX_1
  93.  rem If %2 is _full_path_&_file_name_ of (alternate) $GETFNX$.AUX then continue
  94. if exist %2 goto AuxPathChecked
  95.  rem If %2 is path only to explicit $GETFNX$.AUX then restart GETFNX (%0) with
  96.  rem _full_path_&_file_name_ as the first parameter
  97. if exist %2$GETFNX$.AUX %0 %1 %2$GETFNX$.AUX
  98.  rem %2 has been specified by the user, but $GETFNX$.AUX could not be found:
  99. echo *** Auxiliary path[file] %2 is incorrect, file $GETFNX$.AUX not found.
  100. echo     Now trying to find $GETFNX$.AUX using path (or full file specification):
  101. echo     1. from environment variable GETFNX (path or full file specification)
  102. echo     2. the root directory of C: (C:\) (or automatically any APPENDed path)
  103. echo     3. the root of the current drive (\)
  104. echo     4. the current directory (.\)
  105. echo     5. the parent directory (..\)
  106. echo     6. the same directory as GETFNX.BAT if GETFNX has been called by path
  107. echo     7. from the DOS PATH variable (this may take quite a while)
  108. echo.
  109. goto Determine
  110.  
  111. :AuxPathChecked
  112. echo --- Extract filename and extension from %1 ---
  113. echo echo off>_getfnx1.bat
  114. if not exist _getfnx1.bat goto Impossible
  115. ctty nul
  116. copy _getfnx1.bat+%2 /a _getfnx1.bat /b
  117.  rem Next lines twice with slight difference in order to "dir" a file name without an extension correctly.
  118. if not exist %1. goto HasExt
  119. dir/w %1.|find "    ">>_getfnx1.bat
  120. goto NoExt
  121. :HasExt
  122. dir/w %1 |find "    ">>_getfnx1.bat
  123. :NoExt
  124. call _getfnx1 %0 .getfnx2 %0
  125. del _GETFNX1.BAT
  126. ctty con
  127. echo --- Extracted parts written to GETFNX2.BAT for further use ---
  128. goto end
  129.  
  130. :NotExist
  131. echo Specified file %1 does not exist. ABORT.
  132. goto end
  133.  
  134. :Impossible
  135. echo *** Temporary batch file for further processing could not be created. Abort!
  136. goto end
  137.  
  138. :Help
  139. echo GETFNX File name - extension splitter by Jim Groeneveld, vs. 1.0, 29/1-93.
  140. echo.
  141. echo Syntax: GETFNX [d:][\][path\]filename.ext [[d:][\][path\][auxfilespec]]
  142. echo where d:           = drive: (of concerning file);
  143. echo       path         = absolute or relative path ([\]sub1\sub2.....\);
  144. echo       filename.ext = file specification to split into name and extension;
  145. echo       auxfilespec  = the eventual alt. auxiliary file name for $GETFNX$.AUX;
  146. echo.
  147. echo Output: batch file GETFNX2.BAT with contents:
  148. echo         echo off
  149. echo         %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 filename extension
  150. echo                                  (extension may be 'none')
  151. echo to be called by application using:
  152. echo         call GETFNX2 ownbatch [par1..par7] fn ext
  153. echo User's batch file 'ownbatch.bat' may do anything with these parameters.
  154. :end
  155. goto exit
  156.  
  157. :GETFNX_2
  158. shift
  159. shift
  160. if "%2"=="" %0 .getfnx2 %0 %1 none
  161. echo echo off>GETFNX2.BAT
  162. echo %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %1 %2>>GETFNX2.BAT
  163. goto exit
  164.  
  165. :Path          SUBROUTINE PATH
  166. shift
  167. :ChkPath
  168.  rem Check each path entry for the presence of $GETFNX$.AUX:
  169. if "%1"=="" goto NotFound
  170.  
  171.  rem Check root specifications (ending with a trailing \) firstly:             *
  172. 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 *
  173. 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 *
  174.  rem Path spec is not a root                                                   *
  175.  rem If $RETURN.AUX has been found then restart with location as parameter
  176. if exist %1\$GETFNX$.AUX $GETFNX$ %1\$GETFNX$.AUX
  177. goto NextPath                                                                  *
  178.  
  179. :RootPath                                                                      *
  180.  rem If $RETURN.AUX has been found then restart with location as parameter     *
  181. if exist %1$GETFNX$.AUX $GETFNX$ %1$GETFNX$.AUX
  182.  rem goto NextPath                                                             *
  183. :NextPath                                                                      *
  184.  rem Check next path entry:
  185. shift
  186. goto ChkPath
  187.  
  188. :NotFound
  189.  rem path or auxiliary file not found, indicate
  190. $GETFNX$ .NotFound
  191.  rem Lines marked with * may eventually be deleted all at once resulting in a
  192.  rem slightly changed check algorithm: 1. _with_ '\' and 2. _without_ '\'.
  193.  rem These lines should work, however, with the * included.
  194.  rem goto exit
  195.  
  196. :exit
  197.  rem delete auxiliary file $GETFNX$.BAT if present
  198. if exist $GETFNX$.BAT del $GETFNX$.BAT
  199.