Re: Getting path...
- From: "McKirahan" <News@xxxxxxxxxxxxx>
- Date: Sat, 21 May 2005 17:00:41 -0500
"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.
.
- Follow-Ups:
- Re: Getting path...
- From: Al Dunbar [MS-MVP]
- Re: Getting path...
- References:
- Getting path...
- From: Vince
- Re: Getting path...
- From: Torgeir Bakken \(MVP\)
- Re: Getting path...
- From: McKirahan
- Re: Getting path...
- From: Al Dunbar [MS-MVP]
- Re: Getting path...
- From: McKirahan
- Re: Getting path...
- From: Al Dunbar [MS-MVP]
- Getting path...
- Prev by Date: Re: WSH and WinPE problems
- Next by Date: Is there a way to output this information and create an html form
- Previous by thread: Re: Getting path...
- Next by thread: Re: Getting path...
- Index(es):
Relevant Pages
|