Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DOS Command syntax validation

Posted on 2011-09-12
7
Medium Priority
?
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 11

Expert Comment

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

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 500 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 11

Assisted Solution

by:Ove
Ove earned 500 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 58

Assisted Solution

by:Bill Prew
Bill Prew earned 500 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 500 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

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 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