Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, July 2007
Check for valid path name


Message 1 in thread

I have to check if a QString is a valid path name. There is a function that parses my QString and checks it for me? I have searched in QDir, QFile and QFileInfo classes but I haven't found...

Thanks!


------------------------------------------------------
Leggi GRATIS le tue mail con il telefonino i-mode? di Wind
http://i-mode.wind.it/


--
 [ signature omitted ] 

Message 2 in thread

      bool QDir::exists ( const QString
      <http://zorro/developpement/documentation/qt4.3.0/html/qstring.html>
      & /name/ ) const

Returns true if the directory called /name/ exists; otherwise returns false

but If you parsed qdir doc, maybe I don't understand what you want to 
do?....

fabiodago@xxxxxxxxx a écrit :

>I have to check if a QString is a valid path name. There is a function that parses my QString and checks it for me? I have searched in QDir, QFile and QFileInfo classes but I haven't found...
>
>Thanks!
>
>
>------------------------------------------------------
>Leggi GRATIS le tue mail con il telefonino i-mode^(TM) di Wind
>http://i-mode.wind.it/
>
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>
>
>  
>


Message 3 in thread

veronique.lefrere@xxxxxx schrieb:
> 
> 
> 
>       bool QDir::exists ( const QString
>       <http://zorro/developpement/documentation/qt4.3.0/html/qstring.html>
>       & /name/ ) const
> 
> Returns true if the directory called /name/ exists; otherwise returns false
> 
> but If you parsed qdir doc, maybe I don't understand what you want to 
> do?....

As the subject of this post suggests he does not want to know whether a 
file with a given path exists, but if the path itself is a valid path, 
i.e. well-formed (regardless of the corresponding file exists or not).

For example on Windows "c:/this/is/bad" would be considered bad, or even 
\this\is\bad\on\windows\too (no drive-letter), whereas c:\this\is\good 
or c:\this\is\good\ or even \\host\shared\folder\is\good\too is good. On 
Unix /this/would/be/good whereas \this\would\be\bad etc.

AFAIK there is no such Qt functionality (also note that Qt functions 
don't care about '\' vs. '/' - they accept both forms (working 
internally with '/') in most of their methods.

Cheers, Oliver

--
 [ signature omitted ] 

Message 4 in thread

> As the subject of this post suggests he does not want to know whether
a
> file with a given path exists, but if the path itself is a valid path,
> i.e. well-formed (regardless of the corresponding file exists or not).
> 
> For example on Windows "c:/this/is/bad" would be considered bad, or
even
> \this\is\bad\on\windows\too (no drive-letter), whereas c:\this\is\good
> or c:\this\is\good\ or even \\host\shared\folder\is\good\too is good.
On
> Unix /this/would/be/good whereas \this\would\be\bad etc.
> 
> AFAIK there is no such Qt functionality (also note that Qt functions
> don't care about '\' vs. '/' - they accept both forms (working
> internally with '/') in most of their methods.
> 
> Cheers, Oliver
> 
I think what the OP wants could be a pretty simple regular expression,
optional drive, + a list of 0 or more strings with seperators...

Scott

--
 [ signature omitted ] 

Message 5 in thread

On 7/13/07, Scott Aron Bloom <scott@xxxxxxxxxxxx> wrote:
> > As the subject of this post suggests he does not want to know whether
> a
> > file with a given path exists, but if the path itself is a valid path,
> > i.e. well-formed (regardless of the corresponding file exists or not).
> >
> > For example on Windows "c:/this/is/bad" would be considered bad, or
> even
> > \this\is\bad\on\windows\too (no drive-letter), whereas c:\this\is\good
> > or c:\this\is\good\ or even \\host\shared\folder\is\good\too is good.
> On
> > Unix /this/would/be/good whereas \this\would\be\bad etc.
> >
> > AFAIK there is no such Qt functionality (also note that Qt functions
> > don't care about '\' vs. '/' - they accept both forms (working
> > internally with '/') in most of their methods.
> >
> > Cheers, Oliver
> >
> I think what the OP wants could be a pretty simple regular expression,
> optional drive, + a list of 0 or more strings with seperators...

On *nix, yes, but as Till mentioned Windows supports a wide variety of
path styles (local paths with drive letters, UNC paths, etc). Also,
NTFS supports Alternate Data Streams, which are delimited from the
path name by a colon (e.g. c:\foo.txt:2 or c:\windows:2).

-- 
 [ signature omitted ] 

Message 6 in thread

On 7/13/07, Till Oliver Knoll <oliver.knoll@xxxxxxxxxxx> wrote:
>
> As the subject of this post suggests he does not want to know whether a
> file with a given path exists, but if the path itself is a valid path,
> i.e. well-formed (regardless of the corresponding file exists or not).
>
> For example on Windows "c:/this/is/bad" would be considered bad, or even
> \this\is\bad\on\windows\too (no drive-letter), whereas c:\this\is\good
> or c:\this\is\good\ or even \\host\shared\folder\is\good\too is good. On
> Unix /this/would/be/good whereas \this\would\be\bad etc.

<snip>

It's worth noting that some modern Unixes would accept "\this\would\be\bad"
as a file name (it's a file called "\this\would\be\bad" in the current
directory). If you require absolute paths, then I think the only requirement
is that it starts with a '/' character. Windows seems to have a few more
restrictions, but not many.

Tom

Message 7 in thread

On Friday 13 July 2007 20:11:09 Tom Panning wrote:

> It's worth noting that some modern Unixes would accept "\this\would\be\bad"
> as a file name (it's a file called "\this\would\be\bad" in the current
> directory). If you require absolute paths, then I think the only
> requirement is that it starts with a '/' character. Windows seems to have a
> few more restrictions, but not many.

For UNIX, you can use any characters except / and binary zero '\0'. However, 
many linux environments will consider e.g. http://my.resource.nowhere an http 
resource and treat it as such.

I don't know much about windows. I as recall, e.g. CON: is not valid, since 
that is a device. 

-- 
 [ signature omitted ] 

Message 8 in thread

Till Oliver Knoll wrote:

> For example on Windows "c:/this/is/bad" would be considered bad, or even
> \this\is\bad\on\windows\too (no drive-letter), whereas c:\this\is\good
> or c:\this\is\good\ or even \\host\shared\folder\is\good\too is good. On
> Unix /this/would/be/good whereas \this\would\be\bad etc.

In fact, \path\to\x is perfectly valid on win32, and specifes an
absolute path to a file within the current drive letter.

The only check I would suggest doing on paths to determine if they could
be valid is to ensure that there are no illegal characters on the path.
For win32, you could also check that they began with one of:

	\
	\\
	[A-Za-Z]:\

but that's about it. Similarly, for the Mac, all you'd really want to do
would be check for possible illegal characters.

--
 [ signature omitted ] 

Message 9 in thread

On Sunday 15 July 2007 08:42:56 Craig Ringer wrote:
> The only check I would suggest doing on paths to determine if they could
> be valid is to ensure that there are no illegal characters on the path.
> For win32, you could also check that they began with one of:
>
> 	\
> 	\\
> 	[A-Za-Z]:\
>
> but that's about it.

As I recall, you have to check for stuff like LPT1: NUL: CON: and other 
predefined, hardcoded names. It might be obsolete now, though.

-- 
 [ signature omitted ] 

Message 10 in thread

Esben Mose Hansen schrieb:
>> ...
> As I recall, you have to check for stuff like LPT1: NUL: CON: and other 
> predefined, hardcoded names. It might be obsolete now, though.


So I have learned a few things, too, about paths on Windows and Unix ;) 
Didn't know that \this\path\here is a valid path on Windows (path on the 
current drive) and \this\is\a\valid\unix\file would be accepted on Unix 
(at least some modern Unix).

I knew that this topic has tiny little devils inside, but as it turned 
out more than I could think of ;)

Cheers, Oliver

--
 [ signature omitted ] 

Message 11 in thread

Till Oliver Knoll wrote:
> Esben Mose Hansen schrieb:
>>> ...
>> As I recall, you have to check for stuff like LPT1: NUL: CON: and
>> other predefined, hardcoded names. It might be obsolete now, though.

They're still there as of XP.

prompt> type con
blah1
blah1
blah3
blah3
blah6
blah6
prompt>

it's the same as 'cat', 'cat <&1' or 'cat /dev/stdin' on *nix (only some
UNIXes/shells for the last two).

Thankfully the slightly less prehistoric ports (as used by printers etc)
 don't get globally reserved names, that's only a problem for the legacy
names. So FILE, USB001, etc aren't reserved.

> So I have learned a few things, too, about paths on Windows and Unix ;)
> Didn't know that \this\path\here is a valid path on Windows (path on the
> current drive) and \this\is\a\valid\unix\file would be accepted on Unix
> (at least some modern Unix).
> 
> I knew that this topic has tiny little devils inside, but as it turned
> out more than I could think of ;)

Even if you "validate" a path, what have you learned? That it could
potentially appear as a path on that platform. But does that do you any
real good? Probably not.

You don't know if you have permission to access it, or whether some ACL,
POSIX permission, or special security module (like Trusted Solaris MAC,
SELinux, AppArmour, etc) will deny you access. Even if you can create a
file you can't necessarily read it or delete it; there really aren't any
guarantees. The only reliable way to test if you can perform an
operation is usually to perform it. Even then, transient states (eg out
of disk space, too many open files) could stop it working even though it
worked last time.

--
 [ signature omitted ] 

Message 12 in thread

Craig Ringer schrieb:
> > ...
> Even if you "validate" a path, what have you learned? That it could
> potentially appear as a path on that platform. But does that do you any
> real good? Probably not.

The OP probably wanted to implement some "validating path line edit" 
which shows the path in red or something whenever the user types in some 
invalid path. In that sense it would still be useful.

For the rest you are absolutely right :)

Cheers, Oliver

--
 [ signature omitted ] 

Message 13 in thread

Hi,

> I have to check if a QString is a valid path name. There is a function that parses my QString and checks it for me? I have searched in QDir, QFile and QFileInfo classes but I haven't found...

Where does the path name come from? How is the QString initialized?

--
 [ signature omitted ]