Solved

MS-DOS batch file (IF and FINSTR)

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

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 56

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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

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