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 >
Text File  |  1993-01-29  |  9KB  |  231 lines

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