Log of a batch file...

C

Charles Theodore

Hi,

Running windows xp and don't want third party to accomplish the task.

Have found two ways in this newsgroup to make the task, but it is not
exactly correct.

I want to be able to log the output only when the batch file make an
action in the directories. In this example, be able to create an INPUT
dir when needed and log it in logfile.log and not log all the
processing. Is it possible?

A) batch.cmd>>lofile.log >2&1 ---> only output the entire processing
of batch.

B) Put the following code in the existing batch file: ---> only output
the entire processing of batch.

@ECHO ON & setlocal
call :Logit>>batch.log 2>&1
exit /b 0
:Logit
set pathx=\\filesrv1\MSI
for /f "delims=" %%A in ('dir/B/S/A-D "%pathx%\*.zap"'
) do if not exist "%%~dpAINPUT" md "%%~dpAINPUT"

Thanks in advance.
 
M

Matthias Tacke

Charles said:
Hi,

Running windows xp and don't want third party to accomplish the task.

Have found two ways in this newsgroup to make the task, but it is not
exactly correct.

I want to be able to log the output only when the batch file make an
action in the directories. In this example, be able to create an INPUT
dir when needed and log it in logfile.log and not log all the
processing. Is it possible?

A) batch.cmd>>lofile.log >2&1 ---> only output the entire processing
of batch.

B) Put the following code in the existing batch file: ---> only output
the entire processing of batch.
@ECHO ON & setlocal
set log=batch.log
set pathx=\\filesrv1\MSI
for /f "delims=" %%A in ('dir/B/S/A-D "%pathx%\*.zap"'
) do if not exist "%%~dpAINPUT" (
md "%%~dpAINPUT"
echo/created %%~dpAINPUT at %date% %time%>>%log%
)
 
C

Charles Theodore

Matthias Tacke said:
@ECHO ON & setlocal
set log=batch.log
set pathx=\\filesrv1\MSI
for /f "delims=" %%A in ('dir/B/S/A-D "%pathx%\*.zap"'
) do if not exist "%%~dpAINPUT" (
md "%%~dpAINPUT"
echo/created %%~dpAINPUT at %date% %time%>>%log%
)

Awesome !!!

Thank you Mattias, exactly as requestered!

Have a nice day!
 
C

Charles Theodore

Hello Matthias,

Unfortunately, it does not make all the work... Let me explain why.

First time the script has been run, it write all the makedirs
operations in the log, even if a partial amount of the dirs already
been exists. The batch does not have to log something if the directory
already exist.

Second time the script has been run, it's the same scenario and append
exactly the same routine output to the log file.

The logfile format is great, so nothing to change.

Wondering how to grabout the %errorlevel% when the mkdir operation is
created and if and only if after this successful operation, write the
creation of the directory in the logfile.

Thank you in advance.

Charles
 
M

Matthias Tacke

Charles Theodore wrote:
Hello Matthias,

Unfortunately, it does not make all the work... Let me explain why.

First time the script has been run, it write all the makedirs
operations in the log, even if a partial amount of the dirs already
been exists. The batch does not have to log something if the directory
already exist.
May be an issue with expansion or temporary unavailability of the folder
Second time the script has been run, it's the same scenario and append
exactly the same routine output to the log file.

The logfile format is great, so nothing to change.

Wondering how to grabout the %errorlevel% when the mkdir operation is
created and if and only if after this successful operation, write the
creation of the directory in the logfile.

Thank you in advance.

Charles

I changed the logic and hope this works better.

::MK_input.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::
@ECHO Off
setlocal
set log=batch.log
set pathx=\\filesrv1\MSI
for /f "delims=" %%A in ('dir/B/S/AD "%pathx%"') do (
if exist "%%A\*.zap" if NOT exist "%%A\INPUT" call :sub "%%A"
)
goto :eof
:sub
set INPUT="%~1\INPUT"
md %INPUT%||:):MK_input.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::

HTH
 
C

Charles Theodore

Matthias Tacke said:
Charles Theodore wrote:

May be an issue with expansion or temporary unavailability of the folder


I changed the logic and hope this works better.

::MK_input.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::
@ECHO Off
setlocal
set log=batch.log
set pathx=\\filesrv1\MSI
for /f "delims=" %%A in ('dir/B/S/AD "%pathx%"') do (
if exist "%%A\*.zap" if NOT exist "%%A\INPUT" call :sub "%%A"
)
goto :eof
:sub
set INPUT="%~1\INPUT"
md %INPUT%||(
::MK_input.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::

HTH

Matthias, you're in business!!! Congrutulations!!!

To make more directories and log it, here is my small contribution:

::MK_input.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off & setlocal
set log=batch.log
set pathx=\\filesrv1\MSI
for /f "delims=" %%A in ('dir/B/S/AD "%pathx%"') do (
if exist "%%A\*.zap" if NOT exist "%%A\INPUT1" call :mdinput1 "%%A"
if exist "%%A\*.zap" if NOT exist "%%A\INPUT2" call :mdinput2 "%%A"
)
goto :eof

:mdinput1
set INPUT1="%~1\INPUT1"
md %INPUT1%||(
:mdinput2
set INPUT2="%~1\INPUT2"
md %INPUT2%||:):MK_input.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::::
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top