Help! Help! - Simple search and store results in 1 of 3 file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
smehnert
Posts: 2
Joined: 11 Feb 2010 03:57

Help! Help! - Simple search and store results in 1 of 3 file

#1 Post by smehnert » 11 Feb 2010 04:10

I would like to search for a missing windows file on the pc...
then depending on the result store the result in 2 of 3 files along with the computer name..

The process is;
search for file MSCOMC2.OCX...
store date and time of search and computer name and "File Found"(or "Not Found") result in a file called search.txt
and if the file was found store the same information in Filefound.txt
and if the file was not found store the same information in FileNotFound.txt

I would like to sepearte the results by commas in the text file... and I need to be able or the results to append to as many searches will be performed.

What I have so far is(not much);

echo %computername% >> results.txt
cd c:\
dir "MSCOMCT2.OCX" /s >> \\glkas0676\tm1data\results.txt REM BUT THIS GIVES ME THE COMPLETE RESULT NOT THE FOUND OR NOT FOUND.

Simon

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Help! Help! - Simple search and store results in 1 of 3 file

#2 Post by aGerman » 11 Feb 2010 07:03

smehnert

To append the different results to the same line is IMHO not a good idea, because batch can't handle strings >1024 characters.
Figure out if this code would work for you.

Code: Select all

@echo off &setlocal
set "outfile=results.txt"

pushd "C:\"
for /f "delims=" %%a in ('dir /a-d /b /s "MSCOMCT2.OCX"') do set "fileName=%%a"
popd

if not defined fileName (
  >>"%outfile%" echo %date% %time:~,8%,%computername%,file "MSCOMCT2.OCX" not found
) else (
  >>"%outfile%" echo %date% %time:~,8%,%computername%,file "%fileName%" found
)


Regards
aGerman

smehnert
Posts: 2
Joined: 11 Feb 2010 03:57

Re: Help! Help! - Simple search and store results in 1 of 3 file

#3 Post by smehnert » 15 Feb 2010 16:43

Agerman you are a star, thankyou very much.

SMehnert

Post Reply