home *** CD-ROM | disk | FTP | other *** search
- 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
- From: ts@uwasa.fi (Timo Salmi)
- Newsgroups: comp.os.msdos.programmer
- Subject: Re: A batch programming contest for you
- Message-ID: <1992Aug20.181648.24207@uwasa.fi>
- Date: 20 Aug 92 18:16:48 GMT
- References: <1992Aug18.052017.3758@uwasa.fi> <1992Aug19.153902.6706@spuddy.uucp>
- Organization: University of Vaasa, Finland
- Lines: 67
-
- In article <1992Aug19.153902.6706@spuddy.uucp> sweh@spuddy.uucp (Stephen Harris) writes:
- >In article <1992Aug18.052017.3758@uwasa.fi> ts@uwasa.fi (Timo Salmi) writes:
- >>I have a puzzle for you gentle fellow programmers who are interested
- >>in batch programming. The task is the following. With the standard
- >>batch commands write a batch that returns the extension of the
- >>(file) name given to the batch as the parameter (%1). No external
- >>commands or programs are allowed to perform the task.
-
- > for %%a in (/%x%) do set y=%%a
-
- **** Boing ***** Boing ***** Boing ***** Boing ***** Boing *****
-
- BINGO! This is the key trick. Mine is based on this too, so here
- goes then. And my compliments to everyone. Participation is its
- own reward and we all are winners. Incidentally the /%x% (the slash
- is essential) is interepted as two different arguments. The first
- letter of %x% and the rest of it. That information was published by
- the PC-Magazine, but the idea using it to this task at hand was
- fully due to yours truly.
-
- All the best, Timo
-
- @echo off
-
- if "%1"=="" goto _noparam
-
- for %%f in (%1) do if "%%f"=="%1" goto _nowilds
- Echo Wildcards are not allowed
- goto _out
-
- :_nowilds
- set exten_=%1
- :_next
- set prev_=%exten_%
- for %%f in (/%exten_%) do set exten_=%%f
- if ".%exten_%"=="%prev_%" goto _extfound
- if not "%exten_%"=="%prev_%" goto _next
- goto _noext
-
- :_extfound
- echo The filename %1 has an extension %exten_%
- goto _out
-
- :_noext
- echo The filename %1 has no extension
- goto _out
-
- :_noparam
- echo Usage: GETEXT [FileName]
-
- :_out
- set exten_=
- set prev_=
-
-
- >PS: Timo, please don't moan at the .UUCP address :-)
-
- A good point actually, because they tend to bounce from this side of
- tings.
-
- > Stephen Harris
-
- ..................................................................
- Prof. Timo Salmi
- Moderating at garbo.uwasa.fi anonymous FTP archives 128.214.87.1
- Faculty of Accounting & Industrial Management; University of Vaasa
- Internet: ts@uwasa.fi Bitnet: salmi@finfun ; SF-65101, Finland
-