Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am getting this error when I use the FIND function in a nested FOR loop and IF statements in a batch file.

'find' is not recognized as an internal or external command operable program or batch file

I am trying to find the biggest files in the directory:

SET /P number=Enter the number of files to find:

for /l %%x in (1,1,!number!) do (

for /r %%h in (*) do (
IF %%x GTR 1 IF !check! geq %%~zh (
IF !check! equ %%~zh (
echo !chkn!
FIND "!chkn!" Biggest.txt
IF %errorlevel% equ 1 set res=notfound
FIND "!chkp!" Biggest.txt
IF %errorlevel% equ 1 set res=notfound
IF "!res!" equ "notfound" (
IF !tes! LSS %%~zh (
SET  tes=%%~zh
SET  name=%%~nh
SET  path=%%~ph
)
)
)
IF !tes! LSS %%~zh (
SET  tes=%%~zh
SET  name=%%~nh
SET  path=%%~ph
)
)
IF %%x equ 1 (
IF !tes! LSS %%~zh (
SET  tes=%%~zh
SET  name=%%~nh
SET  path=%%~ph
)
)
)

SET check=!tes!
SET chkn=!name!
SET chkp=!path!

echo !chkn!
echo !check!

echo %%x number: >> Biggest.txt
echo name = !chkn! >> Biggest.txt
echo size = !check! >> Biggest.txt
echo path = !chkp! >> Biggest.txt
echo file is created
SET tes=0
)
share|improve this question
    
you reset search path in your statements under some conditions. As soon as you do, cmd will not be able to find find (pun intended) and will fail. Change your path variable to different name –  wmz Aug 6 '12 at 11:11
    
Yeah..you are correct!!! I need to change the variable 'path' to something else. Thanks a lot!!!! –  Sachin Aug 6 '12 at 14:58
add comment

1 Answer

up vote 1 down vote accepted

Despite the lack of detail, I would guess your Find command doesn't use c:\windows\system32\

Does this work

SET /P number=Enter the number of files to find:

for /l %%x in (1,1,!number!) do (

for /r %%h in (*) do (
IF %%x GTR 1 IF !check! geq %%~zh (
IF !check! equ %%~zh (
echo !chkn!
c:\windows\system32\FIND "!chkn!" Biggest.txt
IF %errorlevel% equ 1 set res=notfound
c:\windows\system32\FIND "!chkp!" Biggest.txt
IF %errorlevel% equ 1 set res=notfound
IF "!res!" equ "notfound" (
IF !tes! LSS %%~zh (
SET  tes=%%~zh
SET  name=%%~nh
SET  path=%%~ph
)
)
)
IF !tes! LSS %%~zh (
SET  tes=%%~zh
SET  name=%%~nh
SET  path=%%~ph
)
)
IF %%x equ 1 (
IF !tes! LSS %%~zh (
SET  tes=%%~zh
SET  name=%%~nh
SET  path=%%~ph
)
)
)

SET check=!tes!
SET chkn=!name!
SET chkp=!path!

echo !chkn!
echo !check!

echo %%x number: >> Biggest.txt
echo name = !chkn! >> Biggest.txt
echo size = !check! >> Biggest.txt
echo path = !chkp! >> Biggest.txt
echo file is created
SET tes=0
)
share|improve this answer
    
But FIND is working when I am running some other batch file –  Sachin Aug 6 '12 at 10:42
    
Yeah....This worked. Thank you very much !! You are right but I don't know why FIND was working in other batch file. –  Sachin Aug 6 '12 at 10:46
    
Glad it worked for you. –  Dave Rook Aug 6 '12 at 10:47
    
your solution works, but root cause is different than what you guessed (see my comment on question). Would you care to edit? –  wmz Aug 6 '12 at 11:36
    
Thanks wmz....you are correct!! –  Sachin Aug 6 '12 at 14:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.