1.

Solve : Stop searching after file is found?

Answer»

How could I make my batch stop LOOKING for a file once it has found it?

What I mean is I have this code:

Code: [Select]@echo off
echo Type in the name of the file you want to find and delete with the extension
echo.
set /p name=
cd\
del %name% /s /p

Now it works fine, but once it prompts you on whether you want to delete the file or not (and you answer "yes") it will delete the file BUT keeps on searching for more files with that name.
Is there anyway to stop this?

So that RIGHT when it deletes the file, it will stop searching?

Thanks.Quote from: fish on March 14, 2011, 01:46:04 PM

Why stop the search after one find?
Because it's time consuming.

Quote
If the file is dangerous all copies should be found.
Yes. With an actual malware utility dangerous files can be found. However since they are USING a batch file they probably aren't trying to write their own malware scanner, because that would be foolish. Additionally, they make no implication that they are, or that the file's they are trying to find are "dangerous".

EDIT: GUESS I may as well ADDRESS the Original Post

you'd would need to not use del /s; instead you would basically need to roll your own routine and search for files yourself. I think maybe FORFILES or a for switch could be used for that. (for /f perhaps)



something like this would do it...

set filename=find this file.txt
for /f "delims=" %%F in ('dir /b /s "%filename%"') do (
del "%%F"
goto jump
)
:jump
echo done

I see Billfish is still around...

Quote from: Salmon Trout on March 14, 2011, 02:20:22 PM
something like this would do it...

set filename=find this file.txt
for /f "delims=" %%F in ('dir /b /s "%filename%"') do (
del "%%F"
goto jump
)
:jump
echo done

I see Billfish is still around...

Wow thank you so much! Works perfectly


Discussion

No Comment Found