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

  1. Path: sparky!uunet!dtix!darwin.sura.net!Sirius.dfn.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!news.funet.fi!uwasa.fi!ts
  2. From: ts@uwasa.fi (Timo Salmi)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: Re: A batch programming contest for you
  5. Message-ID: <1992Aug20.181648.24207@uwasa.fi>
  6. Date: 20 Aug 92 18:16:48 GMT
  7. References: <1992Aug18.052017.3758@uwasa.fi> <1992Aug19.153902.6706@spuddy.uucp>
  8. Organization: University of Vaasa, Finland
  9. Lines: 67
  10.  
  11. In article <1992Aug19.153902.6706@spuddy.uucp> sweh@spuddy.uucp (Stephen Harris) writes:
  12. >In article <1992Aug18.052017.3758@uwasa.fi> ts@uwasa.fi (Timo Salmi) writes:
  13. >>I have a puzzle for you gentle fellow programmers who are interested
  14. >>in batch programming. The task is the following.  With the standard
  15. >>batch commands write a batch that returns the extension of the
  16. >>(file) name given to the batch as the parameter (%1). No external
  17. >>commands or programs are allowed to perform the task.
  18.  
  19. >  for %%a in (/%x%) do set y=%%a
  20.  
  21. **** Boing ***** Boing ***** Boing ***** Boing ***** Boing *****
  22.  
  23. BINGO! This is the key trick.  Mine is based on this too, so here
  24. goes then.  And my compliments to everyone.  Participation is its
  25. own reward and we all are winners.  Incidentally the /%x% (the slash
  26. is essential) is interepted as two different arguments.  The first
  27. letter of %x% and the rest of it.  That information was published by
  28. the PC-Magazine, but the idea using it to this task at hand was
  29. fully due to yours truly. 
  30.  
  31.    All the best, Timo
  32.  
  33. @echo off
  34.  
  35. if "%1"=="" goto _noparam
  36.  
  37. for %%f in (%1) do if "%%f"=="%1" goto _nowilds
  38. Echo Wildcards are not allowed
  39. goto _out
  40.  
  41. :_nowilds
  42. set exten_=%1
  43. :_next
  44. set prev_=%exten_%
  45. for %%f in (/%exten_%) do set exten_=%%f
  46. if ".%exten_%"=="%prev_%" goto _extfound
  47. if not "%exten_%"=="%prev_%" goto _next
  48. goto _noext
  49.  
  50. :_extfound
  51. echo The filename %1 has an extension %exten_%
  52. goto _out
  53.  
  54. :_noext
  55. echo The filename %1 has no extension
  56. goto _out
  57.  
  58. :_noparam
  59. echo Usage: GETEXT [FileName]
  60.  
  61. :_out
  62. set exten_=
  63. set prev_=
  64.  
  65.  
  66. >PS: Timo, please don't moan at the .UUCP address :-)
  67.  
  68. A good point actually, because they tend to bounce from this side of
  69. tings. 
  70.  
  71. >                               Stephen Harris
  72.  
  73. ..................................................................
  74. Prof. Timo Salmi
  75. Moderating at garbo.uwasa.fi anonymous FTP archives 128.214.87.1
  76. Faculty of Accounting & Industrial Management; University of Vaasa
  77. Internet: ts@uwasa.fi Bitnet: salmi@finfun   ; SF-65101, Finland
  78.