Batch File deletion

February 24, 2009 at 15:10:27
Specs: Windows XP
I have very very little batch programming experience so if I could get somebody to write me a batch Id be forever grateful.

I work at a college, and this one file keeps circulating around campus. I need the batch file to search for and delete a file without user input, for example, I want to find and delete all instances of the file "CIMG0057 - Copy.JPG" It would also be awesome if it would copy itself to the c drive and run on startup. Thanks in advance!! Its a huge help!!


See More: Batch File deletion

Report •


#1
February 24, 2009 at 16:49:32
The batch file needs to named removescript.bat:

@echo off
setlocal enabledelayedexpansion
set filename=
reg query hklm\software\microsoft\windows\currentversion\run /v removescript >nul
if "%errorlevel%"=="1" (reg add hklm\software\microsoft\windows\currentversion\run /v removescript /t REG_SZ /d c:\removescript.bat)
if not exist c:\removescript (copy "%cd%\removescript.bat" c:\removescript.bat)
for /R %%a in (.) do (
echo %%a
set filename=%%a
cd !filename!
if EXIST "CIMG0057 - Copy.JPG" (del "CIMG0057 - Copy.JPG")
)


Report •

#2
February 24, 2009 at 19:22:55
That didnt seem to work. It looks like it only scanned the /windows directory. Is this my error?

Report •

#3
February 24, 2009 at 22:50:20
Thats strange. Copy and paste the above script and it should work ok. Describe exactly what you are doing, how your running it. Do you have full access to the system?

Report •

Related Solutions

#4
February 24, 2009 at 22:58:28
To check what it scanned add these lines to the script; it will launch a notepad doc of all the directories it scanned:
@echo off
setlocal enabledelayedexpansion
set filename=
reg query hklm\software\microsoft\windows\currentversion\run /v removescript >nul
if "%errorlevel%"=="1" (reg add hklm\software\microsoft\windows\currentversion\run /v removescript /t REG_SZ /d c:\removescript.bat)
if not exist c:\removescript (copy "%cd%\removescript.bat" c:\removescript.bat)
if exist %temp%\check.txt (del %temp%\check.txt)
for /R %%a in (.) do (
echo %%a
echo %%a >> %temp%\check.txt
set filename=%%a
cd !filename!
if EXIST "CIMG0057 - Copy.JPG" (del "CIMG0057 - Copy.JPG")
)
notepad %temp%\check.txt


Report •

#5
February 25, 2009 at 10:16:47
Alright, so I copied both parts to notepad and saved as removescript.bat as per the directions. I put it in the root of the C drive, the only HDD on this comp. I ran as administrator.

With the added lines, It scans even less it seems and it only prints out:
"C:\Windows\System32\zh-TW\. "


Report •

#6
February 25, 2009 at 10:19:20
i realized that this posted Windows XP as the OS. Its actually Vista. I mustve selected the wrond option by mistake.

Report •


Ask Question