Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need help with batch file

1 view
Skip to first unread message

David

unread,
Jul 3, 2002, 4:27:31 AM7/3/02
to
I want to run a batch file that checks to see if a file exists, then using
'FINDSTR' search for key words and output to a text file which I have
managed to do, where I am getting stuck is there could be more than one
file in the directory which needs to be checked.

This is what I would like the script to do: All happens in one directory
with subdirectories

1. Check to see if there are files in the directory - if so goto part 2, if
not change subdirectory and start again.
2. Fnd string needed from each file and output to textfile.
3. Once all files in this directory have been done, change to next
subdirectory and start again

I have read some amazing things that have been done with the 'FOR' command
and was wondering if it could be acheived using this command.
I am new to batch and I do not know how to use variables and the 'FOR'
command, I cannot seem to find an easy to learn help section.

I would be grateful for some pointers

Regards
David Greenhall

RCC

unread,
Jul 3, 2002, 5:09:29 AM7/3/02
to
"David" <da...@praybourne.co.uk> wrote in message
news:SzyU8.720$x6.27...@newsr2.u-net.net...
FOR has at least two pages of documentation and examples. help for or for /?
Regards,
RCC


Garry Deane

unread,
Jul 4, 2002, 1:01:26 AM7/4/02
to
On Wed, 3 Jul 2002 09:27:31 +0100, "David" <da...@praybourne.co.uk>
wrote:

You could use "FOR /R rootpath ..." to walk the directory tree or "FOR
/F %%a in ('dir /b/s rootpath') ..." to extract the name of each of
the files in 'rootpath' and below. However this is not really
necessary as FINDSTR supports wildcards in the filename parameter and
/S to also search subdirectories.

If you need the FOR approach or to just find out more about FINDSTR, a
useful reference site is http://www.ss64.demon.co.uk/nt/ (as well as
FOR /? and FINDSTR /?).

Garry

David

unread,
Jul 4, 2002, 6:15:12 AM7/4/02
to
Thanks, I have used 'FINDSTR /S' and it works great.

Another question I have is, I am using this command to search through a
directory for log files and output into a textfile (users.txt). Then using
the 'FIND' command search through the text file for username, and again
output to seperate files, (eg: user1.txt, user2.txt ....)

Is there a way to stop it creating the username file if no entry was found?

Regards
David Greenhall

"Garry Deane" <garrydeane_at_yahoo.com.au> wrote in message
news:3d23d3c9...@192.168.0.2...

Garry Deane

unread,
Jul 4, 2002, 7:35:04 AM7/4/02
to
On Thu, 4 Jul 2002 11:15:12 +0100, "David" <da...@praybourne.co.uk>
wrote:

>Thanks, I have used 'FINDSTR /S' and it works great.
>
>Another question I have is, I am using this command to search through a
>directory for log files and output into a textfile (users.txt). Then using
>the 'FIND' command search through the text file for username, and again
>output to seperate files, (eg: user1.txt, user2.txt ....)
>
>Is there a way to stop it creating the username file if no entry was found?

There's several ways. Probably the easiest is to simply delete the
file if there was "no find".

find /i "%user%" < users.txt > %user%.txt
if errorlevel 1 del %user%.txt

Or the following one-liner which is the same thing but uses the 'on
error' symbol '||'.

find /i "%user%" < users.txt > %user%.txt || del %user%.txt

Garry

David

unread,
Jul 4, 2002, 9:55:00 AM7/4/02
to
It works !!!!!

Thanks a lot

Regards
David Greenhall


"Garry Deane" <garrydeane_at_yahoo.com.au> wrote in message

news:3d242f37...@192.168.0.2...

0 new messages