home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / msdos / programm / 8615 < prev    next >
Encoding:
Internet Message Format  |  1992-08-18  |  3.0 KB

  1. Path: sparky!uunet!wupost!sdd.hp.com!swrinde!ringer!mlevis
  2. From: mlevis@ringer.cs.utsa.edu (Mike Levis)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: Re: A batch programming contest for you
  5. Message-ID: <1992Aug19.072440.21996@ringer.cs.utsa.edu>
  6. Date: 19 Aug 92 07:24:40 GMT
  7. References: <1992Aug18.052017.3758@uwasa.fi> <1992Aug18.233207.1159@cs.ubc.ca> <1992Aug19.045036.5132@uwasa.fi>
  8. Organization: University of Texas at San Antonio
  9. Lines: 75
  10.  
  11. In article <1992Aug19.045036.5132@uwasa.fi> ts@uwasa.fi (Timo Salmi) writes:
  12. >In article <1992Aug18.233207.1159@cs.ubc.ca> yogi@cs.ubc.ca (Yossi Gil) writes:
  13. >>I am away from my DOS machine now, but I think that the above ideas
  14. >>will work after some polishing. 
  15. >>
  16. >>    erase echo.*
  17. >>    copy %1 echo.*
  18. >>    for %%f in (echo.*) do %%f > ext 
  19. >>
  20. >>The extension of %1 should be in the file ext now.
  21. >>
  22. >>Joseph (Yossi) Gil                 {alberta,uw-beaver,uunet}!ubc-cs!yogi
  23. >
  24. >@echo off
  25. >rem That's a very inventive trick, Yossi.  I expanded a bit. The snag is
  26. >rem the the file must exist in order to get the extension. Another
  27. >rem question is how do you get the extension name into an environment
  28. >rem variable so that we can utilize it.
  29. >
  30. >if not exist %1 goto _out
  31. >if exist echo.* erase echo.*
  32. >copy %1 echo.* > nul
  33. >for %%f in (echo.*) do %%f > ext
  34. >type ext
  35. >if exist ext erase ext
  36. >:_out
  37.  
  38. I modified this.  The following batch file will work somewhat.
  39. It is not efficient (it copies the file that you want
  40. to find the extension of), and it does not do much
  41. error checking (it fails if the filename has no extension),
  42. but it works if the filename either has an extension or
  43. the filename is not given.
  44.  
  45. It creates a variable xyz to have the filename extension.
  46. It creates (and later deletes) a temporary batch file
  47. called tmp.bat .  Essentially, tmp.bat is a clone of the
  48. original batch file below, but it also has the filename
  49. extension as part as the batch file code.
  50.  
  51. @echo off
  52. set xyz=
  53. if %1.==. goto end_batch
  54. del echo.*
  55. copy %1 echo.* > nul
  56. for %%f in (echo.*) do %%f > tmp.dat
  57. if exist %0 copy %0+tmp.dat tmp.bat > nul
  58. if not exist %0 copy %0.bat+tmp.dat tmp.bat > nul
  59. call tmp.bat
  60. del tmp.bat
  61. :end_batch
  62. if %xyz%.==. set xyz=^Z
  63.  
  64. Important!!!  The ^Z means Control-Z (End of file).  It
  65. must be on the same line as the last command, not on the
  66. line following it.  Since ^Z is on the same line as the
  67. last command, we can append the filename extension to
  68. a copy of the batch file and run the copy to set the
  69. variable.
  70.  
  71. Even though this code works somewhat, I'm sure there is a
  72. much better way of doing it.
  73.  
  74. >..................................................................
  75. >Prof. Timo Salmi
  76. >Moderating at garbo.uwasa.fi anonymous FTP archives 128.214.87.1
  77. >Faculty of Accounting & Industrial Management; University of Vaasa
  78. >Internet: ts@uwasa.fi Bitnet: salmi@finfun   ; SF-65101, Finland
  79.  
  80.  
  81. -- 
  82. ==== Mike Levis   mlevis@ringer.cs.utsa.edu ====
  83. ::   ftp ftp.cs.widener.edu (147.31.254.132)  ::  .--.
  84. ::   for ``The Simpsons'' information.  Get   :: (OS/2)
  85. :::: ``Simpsons'' FAQL in dir /pub/simpsons ::::  ~--~
  86.