Solved

DOS Command syntax validation

Posted on 2011-09-12
7
302 Views
Last Modified: 2012-05-12
Hello,

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
0
Comment
Question by:Charlie_Melega
7 Comments
 
LVL 11

Expert Comment

by:jimbecher
ID: 36525989
if not exist file2 goto done:
del file0
del file1
:done
 
0
 
LVL 37

Expert Comment

by:Gerwin Jansen, EE MVE
ID: 36526116
Will the application open file3, file4, file5 and so on?
0
 
LVL 11

Accepted Solution

by:
jimbecher earned 125 total points
ID: 36526232
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?
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 11

Assisted Solution

by:Ove
Ove earned 125 total points
ID: 36526416
with the following batchfile you'll get what you want:
You'll need some files of the GNU utilities for Win32
from http://unxutils.sourceforge.net/
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 ************************
c:
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 *******************

Ove
0
 
LVL 53

Assisted Solution

by:Bill Prew
Bill Prew earned 125 total points
ID: 36526481
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
:Loop
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

~bp
0
 

Author Comment

by:Charlie_Melega
ID: 36529256

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.
0
 
LVL 13

Assisted Solution

by:5g6tdcv4
5g6tdcv4 earned 125 total points
ID: 36529302
what if you run it in a sandbox, let it do its thing and then dump the sandbox after completion?
http://www.sandboxie.com/
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Server 2012 management. 5 25
DCOM errors in Server 2016 2 36
exchange powershell question 5 34
set-aduser powershell command issue 2 30
This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
A brief introduction to what I consider to be the best editor for PowerShell.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question