Trying to use batch code to parse and archive log files... Errors...

Page 4 of 4 FirstFirst ... 234

  1. Posts : 19
    Windows XP Professional 32bit
    Thread Starter
       #31

    Bingo! That did it. :.)
      My Computer


  2. Posts : 19
    Windows XP Professional 32bit
    Thread Starter
       #32

    One last thing... It seems that an SQL log file is bypassing everything. I'll explain...

    Here's the code I'm using:
    Code:
    @ECHO OFF
    CLS
    
    REM Get today's date
    FOR /F "tokens=*" %%A IN ('DATE/T') DO FOR %%B IN (%%A) DO SET Today=%%B
    
    REM Parse out current Year
    FOR /F "tokens=1-3 delims=/-" %%A IN ("%Today%") DO (
        SET DayMonth=%%A
        SET MonthDay=%%B
        SET Year=%%C
    )
    
    REM Subtract 2 from current year
    set /a strtyr=%Year%-2
    
    IF NOT EXIST "C:\www\projects\ems\EMS_Batch\ICS Archive\archives" MKDIR "C:\www\projects\ems\EMS_Batch\ICS Archive\archives"
    FOR %%G IN ("C:\www\projects\ems\EMS_Batch\blah\*.log") DO (call :PARSE "%%~nG")
    goto:EOF
    
    :parse
    SET filename=%1
    if %filename% == "sqlnet.log" (exit /b)
    IF  %filename:~0,24% == %filename% goto found24
    
    REM Process logfiles with 24 char names
    :found24
    
    REM Skip files that are within current and previous year
    set /a archive_yn=%strtyr%-%filename:~17,4%
    
    if %archive_yn% == -1 goto :EOF
    if %archive_yn% == -2 goto :EOF
    
    set archname=archive_for_card_dumps_%filename:~17,4%.zip
    
    REM Add logfile to archive
    REM Redirection to NUL to suppress messages from 7 zip
    7zip a "C:\www\projects\ems\EMS_Batch\ICS Archive\archives\"%archname% "C:\www\projects\ems\EMS_Batch\blah\"%filename%.log > NUL
    
    REM Delete logfile after archived, no prompt
    ECHO Y | DEL "C:\www\projects\ems\EMS_Batch\blah\"%filename%.log
    goto:EOF
    The part about "sqlnet.log" isn't working. I was thinking in my mind that adding that condition would force the batch program to skip over "sqlnet.log", but it's not... Any idea why?
      My Computer


  3. Posts : 3,371
    W10 Pro desktop, W11 laptop, W11 Pro tablet (all 64-bit)
       #33

    You just want it to skip over sqlnet.log? I'd change the line to:

    Code:
    if %filename% == "sqlnet.log" goto :EOF
    This should work as well:

    Code:
    :parse 
    SET filename=%1 
    IF  %filename:~0,24% == %filename% goto found24
    goto :EOF
      My Computer


  4. Posts : 19
    Windows XP Professional 32bit
    Thread Starter
       #34

    Excellent! That did it, strollin. Thanks again!
      My Computer


 
Page 4 of 4 FirstFirst ... 234

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 13:03.
Find Us