Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

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

15 Nov 2011   #31

Windows XP Professional 32bit

Bingo! That did it. :.)

My System SpecsSystem Spec
16 Nov 2011   #32

Windows XP Professional 32bit

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

Here's the code I'm using:

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")

SET filename=%1
if %filename% == "sqlnet.log" (exit /b)
IF  %filename:~0,24% == %filename% goto found24

REM Process logfiles with 24 char names

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,

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
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 System SpecsSystem Spec
16 Nov 2011   #33

W10 Pro desktop, W10 laptop, W10 laptop, W10 Pro tablet (all 64-bit)

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

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

SET filename=%1 
IF  %filename:~0,24% == %filename% goto found24
goto :EOF
My System SpecsSystem Spec

16 Nov 2011   #34

Windows XP Professional 32bit

Excellent! That did it, strollin. Thanks again!
My System SpecsSystem Spec

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

Thread Tools

Similar help and support threads
Thread Forum
Avoiding Spaghetti Code in Batch Files
I've been reading how to avoid spaghetti code in batch files(Batch files - GOTO, and How To Avoid "Spaghetti Code"). In the example of what spaghetti code is, I realized that the batch file that I use when I logon almost fits this example. Could someone please help me make my batch file more...
General Discussion
How to add to RAR archive 40k files without using windows search.
I have over 40 thousand files I need to archive spread throughout a drive in different folders. I cannot use windows search because the drive cannot be index and will take quite some time to fix and solve. Is there another method that can allow me to search a drive and add to winrar .rar archive?...
General Discussion
Unable to correctly parse lines in a .txt file through batch
Good Afternoon All, This is my first post so if I inadvertently insult anyone through my mannerism I apologize in advance. So the puzzle is that my company creates programs for our clients and would like me to create a batch file that can be placed on the desktop and auto-copy all of the...
General Discussion
removing damaged archive files?
Running win 7. Just scanned my C drive w/ESET and the scan turned up several damaged archived files (see below). Should I: 1. Delete the damaged archived files shown trusting that there won't be any repercussions later? 2. Leave everything as is and forget about it? 3. Any reason not to...
General Discussion
Batch code to read, then move files from one folder to another
I'm new to batch coding, so I was hoping someone could help me out. I need to read several .txt files and search them for a specific string, lets say "key1" and "key2." If the file has key1, then it needs to be moved into directory1. If the file has key2, then it needs to be moved to directory2....
General Discussion

Our Sites

Site Links

About Us

Find 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 03:12.
Twitter Facebook Google+ Seven Forums iOS App Seven Forums Android App