Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
File Deletion - Whitelist
Name: JWelsh Date: August 4, 2009 at 05:36:54 Pacific OS: Windows XP Subcategory: Batch
Comment:
Hey guys,
Wondering if anyone could help with a problem in the following piece of code I can't seem to put my finger on.
It's for recursively deleting OCX files except the ones on the whitelist. I keep getting the error message ( was unexpected at this time. I believe its referring to the line IF %~nx1==%%c (
Am I using the wrong syntax for the IF command or something?
@ECHO OFF
REM.-- Prepare the Command Processor
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
::-----------------------------------------------------------
:: OCX FILES
::-----------------------------------------------------------
dir C:\ /s /b | find /I ".ocx" > ocxfile.txt
for /f "tokens=*" %%A in (ocxfile.txt) do (
set ocxfile=%%A
call :GetFileName "!ocxfile!"
)
:whitelist_blah.ocx
:GetFileName
for /f "tokens=1,* delims=_ " %%b in ('"findstr /b /c:":whitelist_" "%~f0""') do (
IF %~nx1==%%c (
ECHO "Whitelist: %%c"
goto Safe:
)
)
ECHO Deleting %*
del %*
IF EXIST %* ECHO Warning - error deleting %*
:safe
Summary: Relates to an ealier post with title: Batch File deleting files by date? HAD TO CHANGE FOLLOWING TO GET WORKING 1. In Line: for /f "tokens=2" %%i in ('date /t') do set thedate=%%i Change tokens=2 to t...
Summary: I am trying to write a batch file that will delete files in a windows secured temp folder. It is located C:\documents and settings\userprofile\local settings\temporary internet files\OLK* If you can'...