home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.msdos.programmer
- Path: sparky!uunet!gumby!destroyer!ubc-cs!yogi
- From: yogi@cs.ubc.ca (Yossi Gil)
- Subject: Re: A batch programming contest for you
- Message-ID: <1992Aug19.164710.20976@cs.ubc.ca>
- Sender: usenet@cs.ubc.ca (Usenet News)
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- References: <1992Aug18.052017.3758@uwasa.fi> <1992Aug18.233207.1159@cs.ubc.ca> <1992Aug19.045036.5132@uwasa.fi> <1992Aug19.072440.21996@ringer.cs.utsa.edu>
- Date: Wed, 19 Aug 92 16:47:10 GMT
- Lines: 85
-
- mlevis@ringer.cs.utsa.edu (Mike Levis) writes:
-
- >In article <1992Aug19.045036.5132@uwasa.fi> ts@uwasa.fi (Timo Salmi) writes:
- >>In article <1992Aug18.233207.1159@cs.ubc.ca> yogi@cs.ubc.ca (Yossi Gil) writes:
- >>
- >>if not exist %1 goto _out
- >>if exist echo.* erase echo.*
- >>copy %1 echo.* > nul
- >>for %%f in (echo.*) do %%f > ext
- >>type ext
- >>if exist ext erase ext
- >>:_out
-
- >I modified this. The following batch file will work somewhat.
- >It is not efficient (it copies the file that you want
- >to find the extension of), and it does not do much
- >error checking (it fails if the filename has no extension),
- >but it works if the filename either has an extension or
- >the filename is not given.
-
- >It creates a variable xyz to have the filename extension.
- >It creates (and later deletes) a temporary batch file
- >called tmp.bat . Essentially, tmp.bat is a clone of the
- >original batch file below, but it also has the filename
- >extension as part as the batch file code.
-
- >@echo off
- >set xyz=
- >if %1.==. goto end_batch
- >del echo.*
- >copy %1 echo.* > nul
- >for %%f in (echo.*) do %%f > tmp.dat
- >if exist %0 copy %0+tmp.dat tmp.bat > nul
- >if not exist %0 copy %0.bat+tmp.dat tmp.bat > nul
- >call tmp.bat
- >del tmp.bat
- >:end_batch
- >if %xyz%.==. set xyz=^Z
-
- >Important!!! The ^Z means Control-Z (End of file). It
- >must be on the same line as the last command, not on the
- >line following it. Since ^Z is on the same line as the
- >last command, we can append the filename extension to
- >a copy of the batch file and run the copy to set the
- >variable.
-
- >Even though this code works somewhat, I'm sure there is a
- >much better way of doing it.
-
- Perhaps a more elegant variation to the above is (I didn't bother
- with all the chekcs)
-
- copy %1 echo.*
- for %f in (echo.*) do %%f >> %0
- set ext=^Z
-
- This batch file will auto destruct but it is not too difficult to
- remedy this: copy %0 to some tmp and rexecute it. The trick in the
- above is that DOS rereads the batch file after each command. If you
- don't believe it, try the following automodifying batch file:
-
- echo echo >> %0.bat
-
-
-
-
-
-
- >>..................................................................
- >>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
-
-
- >--
- >==== Mike Levis mlevis@ringer.cs.utsa.edu ====
- >:: ftp ftp.cs.widener.edu (147.31.254.132) :: .--.
- >:: for ``The Simpsons'' information. Get :: (OS/2)
- >:::: ``Simpsons'' FAQL in dir /pub/simpsons :::: ~--~
- --
- Joseph (Yossi) Gil {alberta,uw-beaver,uunet}!ubc-cs!yogi
- Dept. of Computer Science yogi@cs.ubc.ca (cs.ubc.ca=137.82.8.5)
- 6356 Agricultural Road., Univ. of B.C., Tel: +1-604-822-8175
- Vancouver, British Columbia, V6T 1Z2, Canada. Fax: +1-604-822-5485
-