Solved

MS-DOS batch file (IF and FINSTR)

Posted on 2010-08-31
3
1,071 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
  • 2
3 Comments
 
LVL 53

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 83

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 53

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to use wail2ban ?? 13 120
file size 9 51
Facebook React and SyntheticEvents 6 67
Copy dir and files with robocopy 2 56
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to dynamically set the form action using jQuery.

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