?
Solved

Append to log in batch script

Posted on 2009-05-01
2
Medium Priority
?
790 Views
Last Modified: 2012-06-27
Hi,
I'm trying to make a this script and it is working(deleting the folders/files I want), the issue is that the logging append function on line 8 after "%%a" does not seem to want to append to the log file. The other lines that are appended  to log file are working fine.
Does anyone have any suggestions/solutions on how I could solve this ?

Thanks for your time/help in advance :)
:: --- BATCH SCRIPT START ---
@ECHO OFF
::---------------------------------------------------------------------------
SET LogFileName=del_folders_with_content.log
SET DIR_Path=E:\IMG00*.*
::---------------------------------------------------------------------------
SETLOCAL
for /f "tokens=*" %%a in ('dir /s /b /ad "%DIR_Path%" 2^>NUL') do rd /s /q "%%a" >> %~dp0%LogFileName%
ECHO.---------------------------------------------------------------------- >> %~dp0%LogFileName%
ECHO Date/Time: %DATE% - %TIME% >> %~dp0%LogFileName%
ECHO.---------------------------------------------------------------------- >> %~dp0%LogFileName%
ENDLOCAL
EXIT
:: --- BATCH SCRIPT END ---

Open in new window

0
Comment
Question by:formulafo
2 Comments
 
LVL 71

Accepted Solution

by:
Qlemo earned 750 total points
ID: 24278105
I do not see any reason for the rd output not being appended to your log, besides dir not finding any folders - an empty for will not log anything for sure. Maybe you should redirect stderr to the console. And, you can try to embrace the whole for in brackets (will speed up logging):

(for /f "tokens=*" %%a in ('dir /s /b /ad "%DIR_Path%" 2^>con') do rd /s /q "%%a") >> %~dp0%LogFileName%



0
 

Author Comment

by:formulafo
ID: 24278496
Thanks Qlemo, it worked with a little change :)
I just changed it to use brackets and kept the 2^>NUL instead of con. So it looks like this now:
:: --- BATCH SCRIPT START ---
@ECHO ON
::---------------------------------------------------------------------------
SET LogFileName=del_folders_with_content.log
SET DIR_Path=E:\IMG00*.*
::---------------------------------------------------------------------------
SETLOCAL
(for /f "tokens=*" %%a in ('dir /s /b /ad "%DIR_Path%" 2^>NUL') do rd /s /q "%%a") >> %~dp0%LogFileName%
ECHO.---------------------------------------------------------------------- >> %~dp0%LogFileName%
ECHO Date/Time: %DATE% - %TIME% >> %~dp0%LogFileName%
ECHO.---------------------------------------------------------------------- >> %~dp0%LogFileName%
ENDLOCAL
PAUSE
EXIT
:: --- BATCH SCRIPT END ---

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question