Solved

MS-DOS batch file (IF and FINSTR)

Posted on 2010-08-31
3
1,074 Views
Last Modified: 2013-11-09
I need a bat file for MS-DOS for delete the file c:\send.txt if in the file c:\log.txt appear "Transfer complete"

Thanks
0
Comment
Question by:alejandro_fernandez
[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
  • 2
3 Comments
 
LVL 55

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 33566252
Here's the simplest way:

@echo off
findstr /i "transfer complete" "c:\log.txt">nul && del "c:\send.txt">NUL

~bp
0
 
LVL 85

Expert Comment

by:oBdA
ID: 33566603
Sorry, but that doesn't work correctly.
'findstr /i "transfer complete"' will actually find any occurrence of "transfer" OR "complete", in other words, it would return errorlevel 0 for "Transfer incomplete" as well as "Transfer stopped" or "Formatting of drive C: complete".

"find" is the easier solution here:
find /i "Transfer complete" "c:\log.txt">nul && del "c:\send.txt">NUL
0
 
LVL 55

Expert Comment

by:Bill Prew
ID: 33566681
Good point, if I had a nickel for every time I forgot that.  Do adjust the FINDSTR approach to handle this we would do:

@echo off
findstr /i /c:"transfer complete" "c:\log.txt">nul && del "c:\send.txt">NUL

~bp
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 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