How to be sure if a string is valid for using with File?


how to be sure if a string passed to File constructor is a valid path ?
parsing the command line and taking user input as a valid file path isn’t safe
if i call File f(commandLine), cause if the user passes a wrong path String… i reach an assert in parseAbsolutePath, or worse in release mode i get called File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName() with a wrong path… how can i be sure if a File can be constructed correctly ?
i thought the file would be constructed correctly, but calling to exists or existsAsFile would return false…

maybe add a isValid function ?


The assertion’s just there as a hint that you’re probably doing something silly, it doesn’t mean that it’ll fail to create the file object.

It’s ok to create a file object with any path, regardless of whether it’s a real path. There are plenty of methods for checking if the file exists after it’s created.


ok jules thanx… just to be sure why in debug mode i get crashes when testing every user-case in the application