Adding BS to paths

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ImOk

    Adding BS to paths

    I need to add a filename to a path under Windows. Sometimes the path
    may have the "\" sometimes not. Is there some function that checks if
    the path does not end in "\" to add it or some quick way of doing this?

    E.g. addBs($path) . $filename;

    The most efficient way I could think of is

    rtim($path,"\\" ) . "\\" . $filename;

    Thanks.

  • Erwin Moller

    #2
    Re: Adding BS to paths

    ImOk wrote:
    [color=blue]
    > I need to add a filename to a path under Windows. Sometimes the path
    > may have the "\" sometimes not. Is there some function that checks if
    > the path does not end in "\" to add it or some quick way of doing this?[/color]

    Hi,

    This is very basic.
    Just check if the last character is a \.
    if not: add it.

    Or alternatively, you can use rtrim indeed as you did.
    [color=blue]
    >
    > E.g. addBs($path) . $filename;
    >
    > The most efficient way I could think of is[/color]

    What do you mean by efficient?
    Is your webserver crashing under the load of this
    end-of-string-manipulation?
    ;-)

    Is something isn't broken, don't fix it.
    Your solution is just fine.

    Regards,
    Erwin Moller
    [color=blue]
    >
    > rtim($path,"\\" ) . "\\" . $filename;
    >
    > Thanks.[/color]

    Comment

    Working...