Help with Exception List

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

Help with Exception List

#1 Post by RElliott63 » 11 Feb 2009 15:17

I'm trying to secure delete files from a hard drive. I have the following but, I can't seem to find the glitch. The issue seems to be that the *SkipPath* variable isn't flagging properly coming out of the ExceptPath routine so that the RemoveFile routine knows whether to skip removing the file based on the Exception List.

Help!

Code: Select all

@Echo Off

 SETLOCAL ENABLEEXTENSIONS
 SETLOCAL ENABLEDELAYEDEXPANSION

 :: Local Variables
 Set "Log=%Temp%\%xxStore%-SecDel-%dYYMMDD%-%tHHMMSS%.csv"
 Set "LookUpSet= *File1* *.zip *File2*"
 Set "Exceptions=Lexmark Java Code128 Drivers Oracle SysMgt OfficeScan"
 Set "SkipPath=N"

 :: Process From the Root!
 cd \

:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
:: Main Job
:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

 CLS
 Echo =========================
 Echo Begin:  Looking for Files
 Echo **  Please be Patient! **
 Echo =========================
 Call :LogMsg B "Looking for Cash Files"
   
 For /F "Delims=" %%F In ('Dir /B/S %LookUpSet%') Do (
     Set "f=%%~nxF"
     Set "p=%%~pF"
     Set "s=%%~zF"

     Cls
     Echo;
     Echo =======================
     Echo  Looking Through Files
     Echo =======================
     Echo;
     Echo Path: !p!
     Echo File: !f! : !s!
     Echo;
     
     Call :RemoveFile
     
     If /I [!SkipPath!] EQU [N] (
        Find "!p!" %PurgeFolders% >NUL
        If Not ErrorLevel 1 (Echo !p! >> %PurgeFolders%)
     )
     Pause
 )
 
 Echo;
 Echo ================================
 Echo  Finished Looking Through Files
 Echo ================================

 Call :LogMsg E "Looking for Cash Files"
 Call :LogMsg E "Job Finished"

:Exit
 Echo ... Job Finished!
 
 Goto:EOF

EndLocal

:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
:: File Removal
:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 :RemoveFile

 Call :ExceptPath
 
 If [!SkipPath!] EQU [N] (
    CD /D !p!
       
    Echo --Removing File:  !f!
    Echo ** SDelete -p 5 !f! **
 )
 
 Goto:EOF

:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
:: See if we need to skip this path deletion
:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 :ExceptPath

 :: Check for an exception ID
 For /D %%E in (%Exceptions%) Do (
     Set "SkipPath=N"
     Echo !p! | Find "%%E" >NUL
     If Not ErrorLevel 1 (Set "SkipPath=Y")
 )
 
 Goto:EOF

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#2 Post by RElliott63 » 18 Feb 2009 08:58

Just in case anyone is interested, this is the final script that works. For some reason, setting the "SkipPath" variable inside the Do-Loop in the ExceptPath Subroutine didn't do the assignment.

-R

Code: Select all

 Call :LogMsg B "Looking for Register Files at Reg# %1"
   
 For /F "Delims=" %%F In ('Dir /B/S %LookUpSet%') Do (
     Set "f=%%~nxF"
     Set "p=%%~pF"
     Set "s=%%~zF"

     Cls
     Echo;
     Echo ==========================================
     Echo  Looking Through REGISTER Files on Reg# %1
     Echo ==========================================
     Echo;
     Echo Path: !p!
     Echo File: -!s!- !f!
     Echo;
     
     Call :ExceptPath
     If [!SkipPath!] EQU [N] (
        Call :RemoveFile
     ) 
     
 )

 :ExceptPath

 Echo !p! > %Temp%\Path

 :: Check for an exception ID
 For /D %%E in (%Exceptions%) Do (
     Find /i "%%E" %Temp%\Path
     If Not ErrorLevel 1 (Goto FoundOne)
 )
 
 Set "SkipPath=N"
 Goto:EOF
 
 :FoundOne
 Set "SkipPath=Y"
 
 Goto:EOF

 :RemoveFile

    CD /D !p!
       
    Echo --SDeleting-- ...
    Call :LogMsg M "SDeleting !f!"
    SDelete -p 5 !f!"
 
 Goto:EOF



Post Reply