home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / msdos / programm / 8616 < prev    next >
Encoding:
Text File  |  1992-08-19  |  2.3 KB  |  64 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.083033.12517@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>
  9. Date: Wed, 19 Aug 92 08:30:33 GMT
  10. Lines: 52
  11.  
  12. ts@uwasa.fi (Timo Salmi) writes:
  13.  
  14. >In article <1992Aug18.233207.1159@cs.ubc.ca> yogi@cs.ubc.ca (Yossi Gil) writes:
  15. >>I am away from my DOS machine now, but I think that the above ideas
  16. >>will work after some polishing. 
  17. >>
  18. >>    erase echo.*
  19. >>    copy %1 echo.*
  20. >>    for %%f in (echo.*) do %%f > ext 
  21. >>
  22. >>The extension of %1 should be in the file ext now.
  23. >>
  24. >>Joseph (Yossi) Gil                 {alberta,uw-beaver,uunet}!ubc-cs!yogi
  25.  
  26. >@echo off
  27. >rem That's a very inventive trick, Yossi.  I expanded a bit. The snag is
  28. >rem the the file must exist in order to get the extension. Another
  29. >rem question is how do you get the extension name into an environment
  30. >rem variable so that we can utilize it.
  31.  
  32. >if not exist %1 goto _out
  33. >if exist echo.* erase echo.*
  34. >copy %1 echo.* > nul
  35. >for %%f in (echo.*) do %%f > ext
  36. >type ext
  37. >if exist ext erase ext
  38. >:_out
  39.  
  40. Well, here is how to set it into a variable. It is a bit complex,
  41. and I didn't bother to polish, to make even cryptier (as I really
  42. should have) or document. But, as my students often say, it works
  43. so what else is important? 
  44.  
  45. set Z=%%Z%%
  46. set G=%%.ext%%
  47. echo %Z%
  48. copy %1 for%Z%.*
  49. echo set Z= %%%%g in (>c.bat
  50. for %%f in (for%Z%.*) do echo %%f ) do set .ext=%%%%g>> c.bat
  51. echo echo %G% >> c.bat
  52. c.bat
  53.  
  54. >..................................................................
  55. >Prof. Timo Salmi
  56. >Moderating at garbo.uwasa.fi anonymous FTP archives 128.214.87.1
  57. >Faculty of Accounting & Industrial Management; University of Vaasa
  58. >Internet: ts@uwasa.fi Bitnet: salmi@finfun   ; SF-65101, Finland
  59. --
  60. Joseph (Yossi) Gil                 {alberta,uw-beaver,uunet}!ubc-cs!yogi
  61. Dept. of Computer Science          yogi@cs.ubc.ca (cs.ubc.ca=137.82.8.5)
  62. 6356 Agricultural Road., Univ. of B.C.,             Tel: +1-604-822-8175
  63. Vancouver, British Columbia, V6T 1Z2, Canada.       Fax: +1-604-822-5485
  64.