Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FInd/Delete Files Containging String

947 views
Skip to first unread message

end...@yahoo.com

unread,
May 17, 2011, 3:19:57 PM5/17/11
to
I am having trouble creating a batch file to do a scheduled task. The
following works at the command line, but does not work in a batch:

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.

Tom Lavedas

unread,
May 17, 2011, 3:55:26 PM5/17/11
to

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

end...@yahoo.com

unread,
May 17, 2011, 4:11:45 PM5/17/11
to

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

Tom Lavedas

unread,
May 17, 2011, 5:39:17 PM5/17/11
to

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

Todd Vargo

unread,
May 17, 2011, 5:49:23 PM5/17/11
to

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"

0 new messages