DOS Command syntax validation


I have an application that I load via a command line syntax. This application will write debug output to a file and when this file hits 300k, will open the next file incrementing the filename by 1. What I am looking to do via DOS is to delete the original file, file1 and file2 as soon as file2 is opened. That’s it. I don’t want more than 2 files at a time as these file can get large and I don’t want to chew up resources. I am simply trying to figure out how to use DOS to delete these 3 files ONCE File2 is opened.

Thank You
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

if not exist file2 goto done:
del file0
del file1
Gerwin Jansen, EE MVETopic Advisor Commented:
Will the application open file3, file4, file5 and so on?
You have me really, really confused. I thought the application you were running opened those files

You start and application athe the command prompt. It will create debug info starting at file. When file hits 300k it will close file and open file1. When file1 reached 300k it will close file1 and open file2 at which point you want to delete file, file1 and file2 even though you just opened file2?

I guess what I would like to know is what application you are running and can you interject DOS code int to it?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Redefining Cyber Security w/ AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Join our webinar on Sept. 21st to learn more about leveraging AI and machine learning to protect your business.

with the following batchfile you'll get what you want:
You'll need some files of the GNU utilities for Win32
Install /copy them (GNU utilities) to c:\windows\system32.
Pls set your program.-dir in line 2 and the name of your file(s) in line 3 and 4

****************** snip ************************
cd "\program files\myapp"
dir file* /O:D /B > %temp%\myfiles.txt
grep -c file %temp%\myfiles.txt > %temp%\numberoffiles.txt
Set /p numberoffiles= < %temp%\numberoffiles.txt
del %temp%\numberoffiles.txt
IF "%numberoffiles%" GTR "2" (
    head -n-2 %temp%\myfiles.txt > %temp%\willbedeleted.txt
    for /f %%d in (%temp%\willbedeleted.txt) do del "%%d"
************** snap *******************

Bill PrewCommented:
You say "as soon as" the new file is created you want the prior one deleted. There's no easy way to do that. But you could create a BAT script something like below and either have it looping with a small delay between iterations, or you could use Task Scheduler and have it run every 10 or 15 minutes maybe?

@echo off
set BaseDir=c:\temp
set BaseFile=filename
set Prior=-1
set Current=0
set /A Prior+=1
set /A Current+=1
if exist "%BaseDir%\%FileBase%%Current%" (
  if exist "%BaseDir%\%FileBase%%Prior%" (
    del /Q "%BaseDir%\%FileBase%%Prior%"
  goto :Loop

Open in new window

Charlie_MelegaAuthor Commented:

just to clarify,  I am running ProcMon using the following syntax:

procmon /Quiet /LoadConfig TEST_config  /Minimized /BackingFile FILE.PML

this will load ProcMon with the specific config file and stat writing output to FILE.PML. After the file reached approximately 300k in size, it will close and open FILE1.PML and so on. Once FILE2 opens, I  want to delete all instances of FILE.* . I just tested this manually and cannot delete FILE and FILE1 even though both of these files are closed, ProcMon has a lock on them and tey cannot be deleted. Obviously, this is more of a problem with ProcMon I have to deal with than DOS syntax so I will need to re-think this. If anyone has thoughts, I'd welcome them.
what if you run it in a sandbox, let it do its thing and then dump the sandbox after completion?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.