File::withFileExtension() bug?

Am I wrong to expect this code to work?

    File hiddenPic { File {"./.invisible image"}.withFileExtension("png") };
    jassert(hiddenPic.getFileName() == ".invisible image.png");

(The name of hiddenPic ends up as .png)

Yes, that’s the documented behaviour:

Returns a version of this file with a different file extension.

e.g. File ("/moose/fish/foo.txt").withFileExtension ("html") returns "/moose/fish/foo.html"

Thanks @reuk. I think I see now that there is no way to tell an invisible file with no extension (.invisible image) from a visible file with no name (.png). Also, that withFileExtension means ‘replaceFileExtension’ and not ‘addFileExtension’.

Thanks for taking the time. I appreciate your work on the forums and the framework.

1 Like