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
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
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...
>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
Thanks a lot
Regards
David Greenhall
"Garry Deane" <garrydeane_at_yahoo.com.au> wrote in message
news:3d242f37...@192.168.0.2...