Batch File to test if there are unsaved open Notepad files?

Solution 1:

After a bit of experimentation, the following line seems to do the trick.

set np_us=F & tasklist /fi "IMAGENAME eq notepad.exe" /v|find "*" >NUL && set np_us=T

This will return a value of np_us=T if there are Notepad windows with unsaved content open (i.e. ones that have an asterisk in the title), or np_us=F if either Notepad is not running, or there are no Notepad windows with unsaved content open.

There are probably better ways to test the matter, but I have been using the above for a few months and it has yet to my knowledge to throw up a false result.