Link to home
Start Free TrialLog in
Avatar of formulafo
formulafo

asked on

Append to log in batch script

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

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of formulafo
formulafo

ASKER

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