Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need to create a batch file to delete all files listed in a log file .
the log file looks like this:files added 12 :
C:\New Folder\blot.pfh
C:\New Folder\blnt.pfh
C:\New Folder\blrt.pfh
C:\New Folder\blst.pfh
C:\Windows\System\blot.dll
C:\.....Files deleted 3:
...-----------------------
the added files are modified eatch day ... I can't delete theme manualy...
Please help me

Hello, Tiberiu. You've stated your OS as DOS. I must ask if it's really DOS, because many people using NT systems, such as WinXP, think they're on DOS just because they're using the command interpreter, CMD.exe. That's not true.
If you're on Win9x/DOS, read my FAQ:
FAQ #24 - Process a file passing each line to a variable
http://www.batch.hpg.com.br/index.htm#24With the script on that URL, you will be able to process one line at a time from the log file. So, the idea would be to start deletion of files when the line contains "files added" and stop it when it reaches the line containing "files deleted".
Here's the script addapted to your case:
===== BATCH SCRIPT BEGIN =====
@echo offtype LOGFILE.DAT > %TEMP%.\T1.BAT
set dodel=0
echo e100'SET %%1='> %TEMP%\T3.DAT
for %%? in (rcx 7 w q) do echo %%?>> %TEMP%.\T3.DAT
type nul> %TEMP%.\T2.DAT
DEBUG %TEMP%.\T2.DAT < %TEMP%.\T3.DAT > nul:loop
copy %TEMP%.\T1.BAT nul > %TEMP%.\T3.DAT
FIND " 0 " < %TEMP%.\T3.DAT > nul
if not errorlevel=1 goto loopend
copy/y %TEMP%.\T2.DAT+%TEMP%.\T1.BAT %TEMP%.\T3.DAT > nul
FIND "SET %%1=" < %TEMP%.\T3.DAT > %TEMP%.\T1.BAT
call %TEMP%.\T1.BAT FILEecho %FILE% |FIND /I "files deleted" > nul
if not errorlevel=1 goto loopend:: To activate the script, remove "echo.{demo}" from net line
if "%dodel%"=="1" if not "%FILE%"=="" echo.{demo}del %L%echo %FILE% |FIND /I "files added" > nul
if not errorlevel=1 set dodel=1FIND/V "SET %%1=" < %TEMP%.\T3.DAT > %TEMP%.\T1.BAT
goto loop:loopend
for %%? in (T1.BAT T2.DAT T3.DAT) do del %TEMP%.\%%?
for %%? in (dodel FILE) do set %%?=:eof
===== BATCH SCRIPT END =====The script is de-activated. If you run it like that, it will display the actions it would take if active. If those are the desired actions, activate it (read commented lines to do so).
That script was tested under Win98SE.
Now, if you're on a NT system, you should use the FOR /F cmd to process the lines. The rest follows the same idea from the DOS/Win9x script.
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br______________________________________________________

Oops, little bug one script above!!!
Where it says:
if "%dodel%"=="1" if not "%FILE%"=="" echo.{demo}del %L%
It should be:
if "%dodel%"=="1" if not "%FILE%"=="" echo.{demo}del %FILE%
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br______________________________________________________

![]() |
Script + FTP + port
|
DOS Script
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |