for /f "delims=" %F in ('findstr /m "<ad-width>0</ad-width>" *.txt')
do del "%~F"
I am doing a search for string in a group of text files and want to
delete the files that contain that string. I want it to work inside a
batch file that also contains an FTP script. It will search and delete
files with that string and then FTP the remaining files.
I am running the script on Windows 2003 Server.
Thank you.
Most often this kind of problem is a permission problem. Does this
run when the user is logged out? Did you set up the task to run as a
user that has permissions on the folders and files?
_____________________
Tom Lavedas
User has full Administrative permissions. This command works fine if
it is type directly into the command prompt and executed. When it is
placed into a Batch file I get an error "~F" was unexpected at this
time.
I am guessing that since it is in a batch file and not at the command
line it has something to do with how WIndows executes a Batch vs Typed
commands.
> Tom Lavedas
Oh, I missed that you were running it at a command prompt the first
time. In batch files, percent signs in FOR statements need to be
doubled to designate the loop variable. That is, in the batch file,
use this command (all one line) ...
for /f "delims=" %%F in ('findstr /m "<ad-width>0</ad-width>" *.txt')
do del "%%~F"
_____________________
Tom Lavedas
You need to double the percents when running a FOR command in a batch file.
for /f "delims=" %%F in ('findstr /m "<ad-width>0</ad-width>" *.txt')
do del "%%~F"