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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |