File Deletion - Whitelist

August 4, 2009 at 05:36:54
Specs: Windows XP
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


See More: File Deletion - Whitelist

Report •


#1
August 4, 2009 at 14:53:05
Hi JWelsh

Try quotes around and see if that helps.
ie

IF "%~nx1"=="%%c" (
ECHO "Whitelist: %%c"
goto Safe:


Report •

#2
August 5, 2009 at 03:30:26
Works a treat. Thanks dtech

Report •

Related Solutions


Ask Question