Solved

MS-DOS batch file (IF and FINSTR)

Posted on 2010-08-31
3
1,070 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 52

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 52

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now