So it's not "does this filename look like it has an extension", but rather, "does this filename look like it has this particular extension"

No. Not always. Notepad Save As "Text Documents" is like that, but Notepad Save As "All Files" is not like that.

Save as Text Doc "boo.txt" -> saved as boo.txt /\.txt\z/==1 Save as Text Doc "boo" -> saved as boo.txt /\.txt\z/==0 Save as Text Doc "boo." -> saved as boo..txt /\.txt\z/==0 Save as Text Doc "boo.pl" -> saved as boo.pl.txt /\.txt\z/==0 Save as Text Doc "boo. pl" -> saved as boo. pl.txt /\.txt\z/==0 Save as All Files "boo.txt" -> saved as boo.txt '.txt' ne '' Save as All Files "boo" -> saved as boo.txt '' eq '' Save as All Files "boo." -> saved as boo. '.' ne '' Save as All Files "boo.pl" -> saved as boo.pl '.pl' ne '' Save as All Files "boo. pl" -> saved as boo. pl.txt '' eq ''

"Text Doc" does
$path .= '.txt' unless $path =~ /\.txt\z/;
which is what I presumed you had in mind.

"All Files" does
$path = $filename . ($ext eq '' ? '.txt' : $ext);
which is what I had in mind. This is the traditional way. Any extention precludes .txt from being added. Well, any registered extention, since Notepad uses the first method I mentioned to identify extentions.

The "Text Doc" behaviour is related to the Hide Extentions "feature" of Windows. Both of these features are real pains.


In reply to Re^5: AWTDI: Renaming files using regexp by ikegami
in thread AWTDI: Renaming files using regexp by nimdokk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.