Re: Getting path...



"Al Dunbar [MS-MVP]" <alan-no-drub-spam@xxxxxxxxxxx> wrote in message
news:Ok1WPwhXFHA.3728@xxxxxxxxxxxxxxxxxxxxxxx

[snip]

> Most of the scripts I write that deal with files have enough to do with
them
> that an instance of the file system object is required anyway.
>
> > And it returns the filename not the path.
>
> Oops, I misread the post, and should have used this instead:
>
> sPath = FSO.getParentFolderName(sPath)
>
> I also find that relying on its path parsing methods results in a little
> more consistency and readability in my code. You probably took less time
to
> realise that .getFileName was the wrong method in this case than I took to
> come to the (incorrect) conclusion that it was. I made the mistake because
> the intent of the following expression is not as explicit:
>
> sPath = Left(sPath,InStrRev(sPath,"\"))
>
> It will also fail in the event that the elements of a pathname are
delimited
> with "/" instead of "\", as is common in URLs.
>
> /Al
>
>

"torgeir" already posted a "getParentFolderName" solution.

The post asked about the full name of a script not a URL;
thus, "\" is applicable and "/" is not.

I agree that the meaning
sPath = Left(sPath,InStrRev(sPath,"\"))
is not very explicit; however, looking at all three lines

Dim sPath
sPath = WScript.ScriptFullName
sPath = Left(sPath,InStrRev(sPath,"\"))

does suggest that the Path is extracted from the Name.

Anyway, the intention of lots of code isn't always clear which is
why meaningful variable names and comments are often used.


.



Relevant Pages

  • Re: Can I delete Wscript.exe?
    ... > that you can logically filter which scripts are allowed to run? ... This will stop the macro viruses, email viruses, etc. ... Sorry, but if I'm intent on getting in and out as fast as possible - I'm not, ... being routed through 4 continents just to use the file associations it ...
    (Focus-Microsoft)
  • Re: Problem: How to resize FreeBSD "partitions" on a live system?
    ... In my first followup on the subject I noted something to that ... if not as explicit as you do here. ... also has all sorts of scripts that rely on the former location and don't ...
    (comp.unix.bsd.freebsd.misc)
  • Creating my own intellisense, code completion functionality
    ... some very specific scripting needs. ... It is our intent to distribute this to ... analysts so they can write scripts. ...
    (microsoft.public.dotnet.framework.windowsforms)