home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / msdos / programm / 8622 < prev    next >
Encoding:
Text File  |  1992-08-19  |  3.3 KB  |  97 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!gumby!destroyer!ubc-cs!yogi
  3. From: yogi@cs.ubc.ca (Yossi Gil)
  4. Subject: Re: A batch programming contest for you
  5. Message-ID: <1992Aug19.164710.20976@cs.ubc.ca>
  6. Sender: usenet@cs.ubc.ca (Usenet News)
  7. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  8. References: <1992Aug18.052017.3758@uwasa.fi> <1992Aug18.233207.1159@cs.ubc.ca> <1992Aug19.045036.5132@uwasa.fi> <1992Aug19.072440.21996@ringer.cs.utsa.edu>
  9. Date: Wed, 19 Aug 92 16:47:10 GMT
  10. Lines: 85
  11.  
  12. mlevis@ringer.cs.utsa.edu (Mike Levis) writes:
  13.  
  14. >In article <1992Aug19.045036.5132@uwasa.fi> ts@uwasa.fi (Timo Salmi) writes:
  15. >>In article <1992Aug18.233207.1159@cs.ubc.ca> yogi@cs.ubc.ca (Yossi Gil) writes:
  16. >>
  17. >>if not exist %1 goto _out
  18. >>if exist echo.* erase echo.*
  19. >>copy %1 echo.* > nul
  20. >>for %%f in (echo.*) do %%f > ext
  21. >>type ext
  22. >>if exist ext erase ext
  23. >>:_out
  24.  
  25. >I modified this.  The following batch file will work somewhat.
  26. >It is not efficient (it copies the file that you want
  27. >to find the extension of), and it does not do much
  28. >error checking (it fails if the filename has no extension),
  29. >but it works if the filename either has an extension or
  30. >the filename is not given.
  31.  
  32. >It creates a variable xyz to have the filename extension.
  33. >It creates (and later deletes) a temporary batch file
  34. >called tmp.bat .  Essentially, tmp.bat is a clone of the
  35. >original batch file below, but it also has the filename
  36. >extension as part as the batch file code.
  37.  
  38. >@echo off
  39. >set xyz=
  40. >if %1.==. goto end_batch
  41. >del echo.*
  42. >copy %1 echo.* > nul
  43. >for %%f in (echo.*) do %%f > tmp.dat
  44. >if exist %0 copy %0+tmp.dat tmp.bat > nul
  45. >if not exist %0 copy %0.bat+tmp.dat tmp.bat > nul
  46. >call tmp.bat
  47. >del tmp.bat
  48. >:end_batch
  49. >if %xyz%.==. set xyz=^Z
  50.  
  51. >Important!!!  The ^Z means Control-Z (End of file).  It
  52. >must be on the same line as the last command, not on the
  53. >line following it.  Since ^Z is on the same line as the
  54. >last command, we can append the filename extension to
  55. >a copy of the batch file and run the copy to set the
  56. >variable.
  57.  
  58. >Even though this code works somewhat, I'm sure there is a
  59. >much better way of doing it.
  60.  
  61. Perhaps a more elegant variation to the above is (I didn't bother
  62. with all the chekcs)
  63.  
  64. copy %1 echo.*
  65. for %f in (echo.*) do %%f >> %0
  66. set ext=^Z
  67.  
  68. This batch file will auto destruct but it is not too difficult to
  69. remedy this: copy %0 to some tmp and rexecute it. The trick in the
  70. above is that DOS rereads the batch file after each command.  If you
  71. don't believe it, try the following automodifying batch file:
  72.  
  73.     echo echo >> %0.bat
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80. >>..................................................................
  81. >>Prof. Timo Salmi
  82. >>Moderating at garbo.uwasa.fi anonymous FTP archives 128.214.87.1
  83. >>Faculty of Accounting & Industrial Management; University of Vaasa
  84. >>Internet: ts@uwasa.fi Bitnet: salmi@finfun   ; SF-65101, Finland
  85.  
  86.  
  87. >-- 
  88. >==== Mike Levis   mlevis@ringer.cs.utsa.edu ====
  89. >::   ftp ftp.cs.widener.edu (147.31.254.132)  ::  .--.
  90. >::   for ``The Simpsons'' information.  Get   :: (OS/2)
  91. >:::: ``Simpsons'' FAQL in dir /pub/simpsons ::::  ~--~
  92. --
  93. Joseph (Yossi) Gil                 {alberta,uw-beaver,uunet}!ubc-cs!yogi
  94. Dept. of Computer Science          yogi@cs.ubc.ca (cs.ubc.ca=137.82.8.5)
  95. 6356 Agricultural Road., Univ. of B.C.,             Tel: +1-604-822-8175
  96. Vancouver, British Columbia, V6T 1Z2, Canada.       Fax: +1-604-822-5485
  97.