Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!sun-barr!apple!usc!csun!csuna!abcscnuk From: abcscnuk@csuna.csun.edu (Naoto Kimura) Newsgroups: comp.binaries.ibm.pc.d Subject: Re: Looking for a specific utility Message-ID: <2169@csuna.csun.edu> Date: 6 Sep 89 19:50:38 GMT References: <6868@rpi.edu> <20.UUL1.3#5109@pantor.UUCP> Reply-To: abcscnuk@csuna.csun.edu (Naoto Kimura) Organization: CSU Northridge Lines: 109 In article <20.UUL1.3#5109@pantor.UUCP> richard@pantor.UUCP (Richard Sargent) writes: > >I have done this regularly from within DOS. Syntax? Try: > >c> for %f in (*.*) do your_command_line > >Double the % when used in a batch file. > >Of course, there are complications if your_command_line creates new files, >converts *.old to *.new, you can't substitute alternate file name extensions. >In cases like these, I simply use a "new" directory for the output files. > >Example: > >c> for %f in (*.old) do sed /this/that/ %f >..\new\%f > > >I hope this helps. > >Richard Sargent Internet: richard@pantor.UUCP >Systems Analyst UUCP: uunet!pantor!richard One problem... This will fail because DOS will try to open an unnamed file in the directory ..\new. Even if it did work, you'd only get the output of the last sed command. I discovered this about a year ago when I wanted to do something similar. You'll have to write a batch file to handle such things as redirection. For example, you want to do the following: FOR %i IN (0 1 2 3 4 5 6 7 8 9) DO Barf < data%i.old > data%i.new This will not result in what you'd expect. This will result in barf trying to read a file called data.new and output the result to data.old. You need to create a batch file UGH.BAT in some subdirectory which contains the following line: BARF < %1 > %2 Then you type the following at the command line: FOR %i IN (0 1 2 3 4 5 6 7 8 9) DO UGH data%i.old data%i.new Another warning to those who use batch files -- the output of a batch file cannot be redirected unless you run a child COMMAND.COM and redirect its output. Suppose you had a batch file, for example BASEBALL.BAT, and you wanted its output to go to a file called OUT. If you typed: BASEBALL > OUT you would end up with an empty file OUT, and all the output of BASEBALL.BAT will go to the screen. You have to do the following to get the desired result: COMMAND /C BASEBALL > OUT This problem caused me some headaches for a few hours. I had a collection of batch files that created smaller batch files, which then were in turn either chained to or executed under a child command processor. Sometimes the redirection seemed to work, and sometimes it didn't. It made a difference where I happened to run the batch files, as they didn't always use a full pathname to refer to each other. So sometimes, the EXE file would be executed, and other times a BAT would be called :-( Another thing to remember about running the command processor is NEVER redirect its input unless you are running a command from it !!!!! I did this one day, thinking that it would do the same as if I were on a UNIX system running bourne shell. It did what I expected, but unfortunately, it resulted in the parent COMMAND.COM trying to read from the input file I specified for the child COMMAND.COM. I basically had to reboot the computer. Of course, I'm sure most of you have already tried this. Equally annoying was the fact that even if you redirected the output of the GWBASIC interpreter, the screen would always be cleared, and the output would still go to the screen (of course you'd get what you expected in the file -- the output of the program) ! It seems that the BASIC interpreters almost completely ignore DOS's stdin and stdout file handles. I suppose it makes sense since they seem to ignore everything else about DOS. What annoyed me to no end was when I tried to send escape sequences to the ANSI driver, but couldn't. I even tried to open a file "CON" and send my escape sequences to that file, but BASIC just output to the "CON" device as if I was doing a plain PRINT statement to BASIC's standard output device. If you're wondering, I needed to do things like clear to end of page and clear to end of line, insert line, and delete line. I eventually had to get rid of the places where I would've used insert and delete line, and used a subroutine that output the appropriate number of spaces to clear to end of page or line. If you're wondering why I was doing stuff in BASIC, I was moving a program on a TRS-80 over to an IBM-PC -- the customer didn't want me to rewrite the program in some other language because BASIC was all they could understand :-(. I used to have similar complaints about Turbo Pascal, but Borland has fixed the problems with introduction of version 4.0. At least it doesn't try to second-guess what you want when you try to open a DOS device. //-n-\\ Naoto Kimura _____---=======---_____ (abcscnuk@csuna.csun.edu) ====____\ /.. ..\ /____==== // ---\__O__/--- \\ Enterprise... Surrender or we'll \_\ /_/ send back your *&^$% tribbles !!