Computing.Net > Forums > Programming > File Deletion - Whitelist

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

Reply to Message Icon

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



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: August 4, 2009 at 14:53:05 Pacific
Reply:

Hi JWelsh

Try quotes around and see if that helps.
ie

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


0

Response Number 2
Name: JWelsh
Date: August 5, 2009 at 03:30:26 Pacific
Reply:

Works a treat. Thanks dtech


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Rename *.TXT file with 24... If condition



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: File Deletion - Whitelist

Batch File deleting files by date? www.computing.net/answers/programming/batch-file-deleting-files-by-date/15581.html

Batch file delete file by file name www.computing.net/answers/programming/batch-file-delete-file-by-file-name/16849.html

batch files delete secured windows www.computing.net/answers/programming/batch-files-delete-secured-windows-/14395.html