Solved

MS-DOS batch file (IF and FINSTR)

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

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 51

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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 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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

757 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

14 Experts available now in Live!

Get 1:1 Help Now