setExtension removes part of a filename if it contained dot
Closed this issue · 1 comments
tapoton commented
I'm composing a path to a file. The name of this file does not have extension, but it contains a dot (e.g. "fullPath/abc.xyz"). When I try to set the extension for this file (e.g. "txt"), I get not what I expect: "fullPath/abc.txt".
Looking at this code, I understand how it happens.
String setExtension(String path, String extension) =>
withoutExtension(path) + extension;
It looks like a naming problem for me. I have no option so set the extension for the file without extension.
What do you think?
natebosch commented
If you want to add an extension without removing an existing extension (or portion of a filename following a .
) you can do it manually. I would avoid setExtension
or withoutExtension
if you are using file names where the .
does not indicate a file extension.