Computing.Net > Forums > Disk Operating System > Delete files listed in *.log file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Delete files listed in *.log file

Reply to Message Icon

Name: tiberiu gal
Date: November 14, 2002 at 10:50:25 Pacific
OS: DOS
CPU/Ram: N/A
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: November 16, 2002 at 16:04:44 Pacific
Reply:

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#24

With 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 off

type 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 FILE

echo %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=1

FIND/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

______________________________________________________


0

Response Number 2
Name: Secret_Doom
Date: November 16, 2002 at 16:07:17 Pacific
Reply:

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

______________________________________________________


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Script + FTP + port DOS Script



Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Delete files listed in *.log file

Inserting date/time in log file www.computing.net/answers/dos/inserting-datetime-in-log-file/8988.html

deleting multiple lines in txt file www.computing.net/answers/dos/deleting-multiple-lines-in-txt-file/15605.html

Deleteing file in root directory wi www.computing.net/answers/dos/deleteing-file-in-root-directory-wi/12683.html