Jump to content

need some batch help


prophetik music
 Share

Recommended Posts

i'm trying to delete a cookie with specific contents using a batch file. the cookie has the word "eservices" in it. every once and a while it goes nuts and i lose some functionality in my work browser, and i'm trying to get a quick one-click solution for that. here's what i've got.

@ECHO OFF
CD C:\Documents and Settings\%USERNAME%\Local

Settings\Temporary Internet Files
del /Q *eservices*.txt
pause

supposedly, this should delete any cookie with the word "eservices" in it, but i just get an error:

"Could Not Find C:\Documents and Settings\bburr\Local Settings\Temporary Internet

Files\*eservices*.txt"

there's the problem - the cookie's name is some jumble of letters and numbers. i'm trying to delete a cookie that has the word IN it, not in the name.

ideas, anyone? i can get you a copy of the cookie if you want.

Link to comment
Share on other sites

You'd need a for loop and searching for the string inside the file, something like:

file1.bat:

@echo off
cd C:\Documents and Settings\%USERNAME%\Local Settings\Temporary Internet Files
for /f %%a IN ('dir /b *.txt') do call file2.bat %%a
pause

file2.bat:

@echo off
findstr /m "eservices" %1
if %errorlevel% == 0
del /Q %1
pause

I've never done much programming in batch files, but it should go something like this, can't tell if it works because it returns a "file not found" on my pc.

Link to comment
Share on other sites

You'd need a for loop and searching for the string inside the file, something like:

file1.bat:

@echo off
cd C:\Documents and Settings\%USERNAME%\Local Settings\Temporary Internet Files
for /f %%a IN ('dir /b *.txt') do call file2.bat %%a
pause

file2.bat:

@echo off
findstr /m "eservices" %1
if %errorlevel% == 0
del /Q %1
pause

I've never done much programming in batch files, but it should go something like this, can't tell if it works because it returns a "file not found" on my pc.

returns the same here =( i tested it on a folder that only contained a copy of the cookie and it didn't find it.

Link to comment
Share on other sites

getting closer!

@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in ('dir/b *.txt') do (
find /i "eservices" < %%a > nul
if not errorlevel 1 echo del %%a
)
pause

this one only runs locally, but it finds the file. unfortunately, it just prints "del [filename]" and then gives me the press any key dialog, rather than deleting it and then giving me the press any key dialog.

can anyone tell me why this doesn't work? is this permissions or syntax? also, if i can get it to run on a folder rather than locally, that's even better.

Link to comment
Share on other sites

What happens if you remove the 'echo' in front of the del command? I don't know Windows batch files well enough to have coded you a solution, but I do know many of the commands, and echo is used to print stuff out to the screen.

that does it =) i'll test it more tomorrow. only issue is that it appears to permanently delete it, rather than move it to the recycle bin (which would be preferable). time for more testing.

Link to comment
Share on other sites

Yeah, Windows doesn't offer a command-line method of sending stuff to the recycle bin; the command-line stuff is all inherited from DOS, which had no recycle bin. Take a look at this for a few ways to recycle from the command-line (the path to the recycle bin doesn't work on Windows 7, though there's probably some other path that would work).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...