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

Discussion and support for general JUCE issues

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

Postby kraken » Fri Feb 10, 2006 10:48 pm

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 ?
Image
User avatar
kraken
JUCE UberWeenie
 
Posts: 1063
Joined: Wed Feb 09, 2005 10:31 am
Location: Venice, Italy

Postby jules » Sat Feb 11, 2006 11:44 am

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.
User avatar
jules
Fearless Leader
 
Posts: 17193
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Postby kraken » Sat Feb 11, 2006 5:43 pm

ok jules thanx... just to be sure why in debug mode i get crashes when testing every user-case in the application
Image
User avatar
kraken
JUCE UberWeenie
 
Posts: 1063
Joined: Wed Feb 09, 2005 10:31 am
Location: Venice, Italy


Return to General JUCE discussion

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests