Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread:
PathFileExists Fails with Quoted Path?

  1. #1
    Karl E. Peterson Guest

    Default PathFileExists Fails with Quoted Path?

    How very odd. The shell function PathFileExists fails if it's p***ed a
    quoted string. The kind you'd get as a command line parameter as a
    fully qualified filespec, due to the fact that spaces are allowed in
    directory and filenames.

    This one caught me by surprise, with "File not found" errors coming
    from a utility I wrote. Anyone else aware of this?

    Repro:

    Private Declare Function PathIsDirectoryW Lib "shlwapi" (ByVal
    lpszPath As Long) As Boolean
    Private Declare Function PathFileExistsW Lib "shlwapi" (ByVal
    lpszPath As Long) As Boolean

    Public Function PathIsFile(ByVal Path As String) As Boolean
    ' Combines a few functions, to test if path points to existing
    file.
    ' NOTE: These fail with quoted filespecs!
    If PathIsDirectoryW(StrPtr(Path)) = False Then
    If PathFileExistsW(StrPtr(Path)) Then
    PathIsFile = True
    End If
    End If
    End Function

    If you p*** a string that includes the surrounding quotes, essentially:

    "C:\Program Files\Common Files\Microsoft Shared\OFFICE14\MSOXMLED.EXE"

    Still mumbling about the perv***ive ramifications...

    --
    ..NET: It's About Trust!
    Code:
    Content visible to registered users only.


  2. #2
    Karl E. Peterson Guest

    Default Re: PathFileExists Fails with Quoted Path?

    "Nevermind..." Cl***ic case of posting it causing deeper refection.
    OF course that function fails, because quote chars are illegal within
    filenames. D'oh!


    on 4/12/2012, Karl E. Peterson supposed :
    > How very odd. The shell function PathFileExists fails if it's p***ed a
    > quoted string. The kind you'd get as a command line parameter as a fully
    > qualified filespec, due to the fact that spaces are allowed in directory and
    > filenames.
    >
    > This one caught me by surprise, with "File not found" errors coming from a
    > utility I wrote. Anyone else aware of this?
    >
    > Repro:
    >
    > Private Declare Function PathIsDirectoryW Lib "shlwapi" (ByVal lpszPath As
    > Long) As Boolean
    > Private Declare Function PathFileExistsW Lib "shlwapi" (ByVal lpszPath As
    > Long) As Boolean
    >
    > Public Function PathIsFile(ByVal Path As String) As Boolean
    > ' Combines a few functions, to test if path points to existing file.
    > ' NOTE: These fail with quoted filespecs!
    > If PathIsDirectoryW(StrPtr(Path)) = False Then
    > If PathFileExistsW(StrPtr(Path)) Then
    > PathIsFile = True
    > End If
    > End If
    > End Function
    >
    > If you p*** a string that includes the surrounding quotes, essentially:
    >
    > "C:\Program Files\Common Files\Microsoft Shared\OFFICE14\MSOXMLED.EXE"
    >
    > Still mumbling about the perv***ive ramifications...


    --
    ..NET: It's About Trust!
    Code:
    Content visible to registered users only.


  3. #3
    ralph Guest

    Default Re: PathFileExists Fails with Quoted Path?

    On Thu, 12 Apr 2012 15:36:09 -0700, Karl E. Peterson < - >
    wrote:

    >"Nevermind..." Cl***ic case of posting it causing deeper refection.
    >OF course that function fails, because quote chars are illegal within
    >filenames. D'oh!
    >

    ....
    >>
    >> If you p*** a string that includes the surrounding quotes, essentially:
    >>
    >> "C:\Program Files\Common Files\Microsoft Shared\OFFICE14\MSOXMLED.EXE"
    >>
    >> Still mumbling about the perv***ive ramifications...



    Yeah, we just had a thread a while back on that. Double quotes are
    only needed for shell parsers that use a space as a delimiter for
    commands and parameters.

    Unfortunately since a program can never be quite sure how it is
    launched, or the means by which it is delivered, any 'strings'
    received from the outside world need to be tested for leading and
    trailing quotes.

    -ralph
    [DIFF/CVS sources can also be a problem.]

  4. #4
    ObiWan Guest

    Default Re: PathFileExists Fails with Quoted Path?


    > Unfortunately since a program can never be quite sure how it is
    > launched, or the means by which it is delivered, any 'strings'
    > received from the outside world need to be tested for leading and
    > trailing quotes.


    Oh... that's easy, either use whatever API your OS offers or setup your
    own cmdline parser trying to resemble what you need, for example...

    Code:
    Content visible to registered users only.
    the above is easy to translate to VB code and will give you a decent
    cmdline parser turning each *real* arg into a separate array element
    then... ok, you may want to push thing further and (as I did centuries
    ago) also add a "getopt" function like the one used in "C" to parse the
    cmdline args with ease, but that's totally up to you


  5. #5
    Mayayana Guest

    Default Re: PathFileExists Fails with Quoted Path?

    I'm curious why you go to the trouble of API for
    that. Is there some advantage over s VB method
    like the following?

    Public Function FileExists(ByVal sPath As String) As Boolean
    Dim i As Integer
    On Error Resume Next
    i = GetAttr(sPath)
    If (Err = 0) Then
    If (i And vbDirectory) = 0 Then
    FileExists = True
    End If
    End If
    End Function

    Public Function FolderExists(ByVal sPath As String) As Boolean
    On Error Resume Next
    FolderExists = (GetAttr(sPath) And vbDirectory) = vbDirectory
    End Function

    --
    --
    "Karl E. Peterson" < - > wrote in message
    news:jm7lct$qks$ - ...
    | "Nevermind..." Cl***ic case of posting it causing deeper refection.
    | OF course that function fails, because quote chars are illegal within
    | filenames. D'oh!
    |
    |
    | on 4/12/2012, Karl E. Peterson supposed :
    | > How very odd. The shell function PathFileExists fails if it's p***ed a
    | > quoted string. The kind you'd get as a command line parameter as a
    fully
    | > qualified filespec, due to the fact that spaces are allowed in directory
    and
    | > filenames.
    | >
    | > This one caught me by surprise, with "File not found" errors coming from
    a
    | > utility I wrote. Anyone else aware of this?
    | >
    | > Repro:
    | >
    | > Private Declare Function PathIsDirectoryW Lib "shlwapi" (ByVal
    lpszPath As
    | > Long) As Boolean
    | > Private Declare Function PathFileExistsW Lib "shlwapi" (ByVal
    lpszPath As
    | > Long) As Boolean
    | >
    | > Public Function PathIsFile(ByVal Path As String) As Boolean
    | > ' Combines a few functions, to test if path points to existing
    file.
    | > ' NOTE: These fail with quoted filespecs!
    | > If PathIsDirectoryW(StrPtr(Path)) = False Then
    | > If PathFileExistsW(StrPtr(Path)) Then
    | > PathIsFile = True
    | > End If
    | > End If
    | > End Function
    | >
    | > If you p*** a string that includes the surrounding quotes, essentially:
    | >
    | > "C:\Program Files\Common Files\Microsoft Shared\OFFICE14\MSOXMLED.EXE"
    | >
    | > Still mumbling about the perv***ive ramifications...
    |
    | --
    | .NET: It's About Trust!
    |
    Code:
    Content visible to registered users only.
    |
    |



  6. #6
    ralph Guest

    Default Re: PathFileExists Fails with Quoted Path?

    On Fri, 13 Apr 2012 15:23:44 +0200, ObiWan
    < - > wrote:

    >
    >> Unfortunately since a program can never be quite sure how it is
    >> launched, or the means by which it is delivered, any 'strings'
    >> received from the outside world need to be tested for leading and
    >> trailing quotes.

    >
    >Oh... that's easy, either use whatever API your OS offers or setup your
    >own cmdline parser trying to resemble what you need, for example...
    >
    >
    Code:
    Content visible to registered users only.
    >
    >the above is easy to translate to VB code and will give you a decent
    >cmdline parser turning each *real* arg into a separate array element
    >then... ok, you may want to push thing further and (as I did centuries
    >ago) also add a "getopt" function like the one used in "C" to parse the
    >cmdline args with ease, but that's totally up to you


    "Easy" appears to be strictly in the eyes of the beholder. The list of
    Windows developers and shops that adopt a consistent standardized
    application command line protocol (parsing and validation) is
    amazingly small, ... uh, make that tiny. <g>

    The UNIX world does much better. Probably because they spend more time
    in shells and getopt() is practically built-in.

    -ralph

  7. #7
    Tony Toews Guest

    Default Re: PathFileExists Fails with Quoted Path?

    On Thu, 12 Apr 2012 21:54:48 -0500, ralph < - >
    wrote:

    >Yeah, we just had a thread a while back on that. Double quotes are
    >only needed for shell parsers that use a space as a delimiter for
    >commands and parameters.


    Thanks, you and Karl might've just solved a problem a client reported
    yesterday when trying to use a dashboard program with my utility.

    Tony
    --
    Tony Toews, Microsoft Access MVP
    Tony's Main MS Access pages -
    Code:
    Content visible to registered users only.
    Tony's Microsoft Access Blog -
    Code:
    Content visible to registered users only.
    For a convenient utility to keep your users FEs and other files
    updated see
    Code:
    Content visible to registered users only.

  8. #8
    Karl E. Peterson Guest

    Default Re: PathFileExists Fails with Quoted Path?

    ralph explained on 4/12/2012 :
    > Yeah, we just had a thread a while back on that. Double quotes are
    > only needed for shell parsers that use a space as a delimiter for
    > commands and parameters.


    Don't think I saw that thread.

    > Unfortunately since a program can never be quite sure how it is
    > launched, or the means by which it is delivered, any 'strings'
    > received from the outside world need to be tested for leading and
    > trailing quotes.


    Seems that way. And normal in all regards. At the moment, the damned
    thing that's puzzling me is just how those quotes got past my parsing
    routines in the first place! That's the trouble with code you wrote
    decades ago. Heh...

    --
    ..NET: It's About Trust!
    Code:
    Content visible to registered users only.


  9. #9
    Karl E. Peterson Guest

    Default Re: PathFileExists Fails with Quoted Path?

    Mayayana formulated on Friday :
    > I'm curious why you go to the trouble of API for
    > that. Is there some advantage over s VB method
    > like the following?
    >
    > Public Function FileExists(ByVal sPath As String) As Boolean
    > Dim i As Integer
    > On Error Resume Next
    > i = GetAttr(sPath)
    > If (Err = 0) Then
    > If (i And vbDirectory) = 0 Then
    > FileExists = True
    > End If
    > End If
    > End Function


    Well, I was about to say, "No", but it does offer some slight
    advantage. There are files that GetAttr simply bombs on...

    ?fileexists("c:\pagefile.sys")
    False

    So if the routine needs to handle anything you throw at it, there's
    really little choice.

    Why these ones? I was interested in the full sweep of path-related
    shell functions, as some of them seemed useful, and just threw together
    a module that wraps nearly all of them. Now, this module gets added to
    many projects for one reason or another, and at that point there's
    little reason to go looking for (or just typing out) another FileExists
    routine.

    --
    ..NET: It's About Trust!
    Code:
    Content visible to registered users only.


  10. #10
    ObiWan Guest

    Default Re: PathFileExists Fails with Quoted Path?


    > Seems that way. And normal in all regards. At the moment, the
    > damned thing that's puzzling me is just how those quotes got past my
    > parsing routines in the first place! That's the trouble with code
    > you wrote decades ago. Heh...


    well... add sFixedPath = Replace(sPath, Chr(34), "") before calling the
    API and you should be quite ok... given that someone won't be so crazy
    to use "special chars" for a folder name



Page 1 of 3 123 LastLast

Similar Threads

  1. Drive path vs. Network Path S:\Shared\Folder vs. \\NETWORK\USER\FO
    By =?Utf-8?B?QXV0aG9y?= in forum microsoft.public.access.modulesdaovba
    Replies: 4
    Last Post: 28-08-08, 05:31 PM
  2. Lidt OT: konvertering af quoted-printable
    By Jan Birk in forum dk.edb.system.unix
    Replies: 6
    Last Post: 26-08-08, 10:55 AM
  3. the Path specified for the file c:\<path>\outlook.pst is not valid
    By =?Utf-8?B?VGhvbWFzVDIy?= in forum microsoft.public.outlook.general
    Replies: 2
    Last Post: 17-08-08, 09:55 PM
  4. [KNode] Problem mit quoted-printable
    By David Seppi in forum de.comm.software.newsreader
    Replies: 13
    Last Post: 15-08-08, 11:38 AM
  5. Fixing Ant build that fails due to space in path
    By eran in forum comp.lang.java.programmer
    Replies: 8
    Last Post: 08-08-08, 09:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •