Re: Getting path...
- From: "Al Dunbar [MS-MVP]" <alan-no-drub-spam@xxxxxxxxxxx>
- Date: Sun, 22 May 2005 15:12:23 -0600
"McKirahan" <News@xxxxxxxxxxxxx> wrote in message
news:Wbednf4CW6SlMhLfRVn-og@xxxxxxxxxxxxxx
> "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.
Given that the path name itself comes from a call that we know is going to
return "\", the code works. In that context, yes, you are right.
But that does not make using getParentFolderName any less of a correct
solution as a result. The file system accepts paths using "/" instead of
"\", and the same operations may need to be done on URL's in another script.
My recommendation for my approach is that, should one happen to need to work
with URL's, fewer changes would need to be made to accommodate. This isn't
robustness for the sake of code robustness, but robustness for the sake of
the coder.
> 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.
Yes, however one needs to exert more brain cells to see the meaning.
> Anyway, the intention of lots of code isn't always clear which is
> why meaningful variable names and comments are often used.
I cannot agree with you more on that one. Which is why I generally use
variable names that are more meaningful than sPath and include suitable
comments. In my case, at least, I find I can even improve things by using
methods whose names are also descriptive, at least where the situation
allows for this.
/Al
.
- Follow-Ups:
- Re: Getting path...
- From: McKirahan
- 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]
- Re: Getting path...
- From: McKirahan
- Getting path...
- Prev by Date: Re: Query Computer
- Next by Date: Re: Need Help please
- Previous by thread: Re: Getting path...
- Next by thread: Re: Getting path...
- Index(es):
Relevant Pages
|