<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Reliably checking if edited file is unsaved from the command line?]]></title><description><![CDATA[<p dir="auto">I have a script that modifies/adds to a raw file of writing ideas, but I found I forget to save that file before running the script again.</p>
<p dir="auto">So I thought I’d put in a stub to see if the file was in an unsaved state. Here is my PERL code (not that such a check has to be in PERL. I thought I’d show what I was trying to do):</p>
<pre><code class="language-open(C,">my $c;
while ($c = &lt;C&gt;)
{
  if ($c =~ /flip.txt/)
  {
    if ($c =~ /backupFilePath=\"[^\"]/i)
    {
	`$output`;
    Win32::MsgBox("Save wfl.txt before copying over", 0, "Less annoying than overwriting");
    }
    last;
  }
}
close(C);
</code></pre>
<p dir="auto">Here I’m just checking the <code>session.xml</code> file and seeing if the flip.txt entry has a non-empty backupFilePath. And the code isn’t perfect, but it is a good first step. It works pretty well, unless I run the script and edit the file and quickly run the script again. Then, <code>session.xml</code> hasn’t updated soon enough.</p>
<p dir="auto">Is there a better way to check for if a file has been modified in Notepad++? This isn’t a huge deal for me, since 95% of the time it’ll work, and when it doesn’t, I can just re-delete the lines I got rid of. Still, I’d like to be more precise.</p>
<p dir="auto">Thanks!</p>
<p dir="auto">(By the way, if you’re curious about the test case, my file <code>wfl.pl</code> takes in an argument, reads a complete list of English words, and then alphabetically writes out all words starting or ending with the argument-word, with a special annotation if (compound word without argument word) is a word itself. So sometimes I get a few ideas for words based on what my latest try gives me, and I can have binges of saving and deleting text.)</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/13919/reliably-checking-if-edited-file-is-unsaved-from-the-command-line</link><generator>RSS for Node</generator><lastBuildDate>Sun, 07 Jun 2026 07:47:59 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/13919.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 04 Jun 2017 19:49:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Reliably checking if edited file is unsaved from the command line? on Mon, 05 Jun 2017 13:18:59 GMT]]></title><description><![CDATA[<p dir="auto">Your method will mostly work as long as you’ve got Settings &gt; Preferences &gt; Backup correctly enabled, and you have a short enough backup time.  If you want to make sure it’s got enough time to register the changes in the file, add a <code>sleep($time)</code> before the check, where <code>$time</code> matches your NPP backup interval.</p>
<p dir="auto">I would probably add a test for existence of the backup file, not just it being listed in session.xml. (I just ran an experiment, and a minute after my most recent save, when the backup file was gone, session.xml still listed the backup file).  I would also use -M to check the modified-time of both the original and the backup, since I found outdated “backups” in my backup directory that were months out of date (probably remained open after a reboot or crash).</p>
<p dir="auto">Also, if you find that the file hasn’t been saved yet, you could also use <a href="https://metacpan.org/pod/Win32::OLE" rel="nofollow ugc">Win32::OLE</a> or <a href="https://metacpan.org/pod/Win32::GuiTest" rel="nofollow ugc">Win32::GuiTest</a> to force NPP to save the file, if you wanted, instead of just pestering yourself with a message box.  But that’s up to you.</p>
<p dir="auto">PS: <a href="http://learn.perl.org/faq/perlfaq1.html#Whats-the-difference-between-perl-and-Perl" rel="nofollow ugc">Perl is not an acronym</a>: “Perl” is the language, “perl” is the executable/interpreter, “PERL” is a backronym.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/24797</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/24797</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 05 Jun 2017 13:18:59 GMT</pubDate></item></channel></rss>