Batch file to delete 1 file 10 secs after it appears?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
val5662
Posts: 34
Joined: 18 Dec 2013 09:48

Batch file to delete 1 file 10 secs after it appears?

#1 Post by val5662 » 01 Nov 2015 13:01

Hi Guys....
Need help! :|
Using "Task Scheduler" in windows7 32bit is it possible to run a batch file to delete a file 10 seconds after it is made by another program? The batch file would be using windows "forfiles.exe" so I am guessing the start of the batch file would look like
forfiles /p "C:\testfolder\" /s /m zm_model.inf

If this method isn't possible, is there any other way that one file ( zm_model.inf ) be deleted automatically 10 seconds after it is made.
Thanks! :)
Val

Squashman
Expert
Posts: 4487
Joined: 23 Dec 2011 13:59

Re: Batch file to delete 1 file 10 secs after it appears?

#2 Post by Squashman » 01 Nov 2015 14:13

Just use FOR /R to find a file and set an environmental variable. Then do an IF DEFINED variable with a timeout and a delete.

val5662
Posts: 34
Joined: 18 Dec 2013 09:48

Re: Batch file to delete 1 file 10 secs after it appears?

#3 Post by val5662 » 01 Nov 2015 15:26

Squashman....
Thanks....but I just figured it out a few mins before I checked back here.
@echo off
:start
cls
If exist zm_model.inf goto delete
if not exist zm_model.inf goto wait
:delete
color 0a
echo.
echo.
echo.
echo DELETED zm_model.inf EXISTING FILE
echo PRESS ctrl + c TO EXIT THIS LOOPING BATCH FILE
echo.
echo OR LEAVE IT RUNNING IF YOU STILL REQUIRE IT
echo TO DELETE MORE GENERATED zm_model.inf FILES
del zm_model.inf
PING 1.1.1.1 -n 1 -w 10000 >NUL
cls
goto start
:wait
color a0
echo.
echo.
echo.
echo WAITING FOR THE NEXT zm_model.inf TO BE GENERATED
PING 1.1.1.1 -n 1 -w 10000 >NUL
goto start
echo.
echo.
echo.

I just leave this batch running until I am done.
Thanks again! :D
Val

Post Reply