Help!
I have a script here that will not work correctly
according to the InStrRev function rules. When it runs,
the file path comes out really weird. For example, the
path: "C:\Documents and Settings\user1\My
Mail\personal.pst" is coming back "gs\user1\my
mail\personal.pst" instead of just displaying the file
name "personal.pst" like it should. Can someone please
take a look? If you need the rest of the code, let me
know. Basically what I have is a list of file path names
in lstPSTList and I'm trying to trunkate the whole path so
I just get the file name.

strKeys = lstPSTList.Keys
For intPST = 0 To lstPSTList.Count - 1
strPSTFilePath = lstPSTList.Item(strKeys(intPST))
strPSTFile = Right(strPSTFilePath, InStrRev
(strPSTFilePath, "\"))
MsgBox strPSTFile
Next

Re: InStr function not working by Torgeir

Torgeir
Tue Sep 16 13:57:47 CDT 2003

Steve wrote:

> Basically what I have is a list of file path names
> in lstPSTList and I'm trying to trunkate the whole path so
> I just get the file name.
>
> strKeys = lstPSTList.Keys
> For intPST = 0 To lstPSTList.Count - 1
> strPSTFilePath = lstPSTList.Item(strKeys(intPST))
> strPSTFile = Right(strPSTFilePath, InStrRev
> (strPSTFilePath, "\"))
> MsgBox strPSTFile
> Next

Hi

There is nothing wrong with the InStrRev function, you just use the Right
function incorrectly.

This works better:

strPSTFilePath = "C:\Documents and Settings\user1\My Mail\personal.pst"

strPSTFile = Right(strPSTFilePath, Len(strPSTFilePath) -
InStrRev(strPSTFilePath, "\"))
WScript.Echo strPSTFile

' alternatively, you can use Mid:

strPSTFile = Mid(strPSTFilePath, InStrRev(strPSTFilePath, "\") + 1)
WScript.Echo strPSTFile

--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter



Re: InStr function not working by Ray

Ray
Tue Sep 16 14:27:27 CDT 2003

I'm partial to
strPSTFilePath = "\" & "C:\Documents and Settings\user1\My
Mail\personal.pst"
aSplit = Split(strPSTFilePath, "\")
strPSTFile = aSplit(UBound(aSplit))

Ray at work


"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
news:3F675D2B.8683404D@hydro.com...
> Steve wrote:
>
> > Basically what I have is a list of file path names
> > in lstPSTList and I'm trying to trunkate the whole path so
> > I just get the file name.
> >
> > strKeys = lstPSTList.Keys
> > For intPST = 0 To lstPSTList.Count - 1
> > strPSTFilePath = lstPSTList.Item(strKeys(intPST))
> > strPSTFile = Right(strPSTFilePath, InStrRev
> > (strPSTFilePath, "\"))
> > MsgBox strPSTFile
> > Next
>
> Hi
>
> There is nothing wrong with the InStrRev function, you just use the Right
> function incorrectly.
>
> This works better:
>
> strPSTFilePath = "C:\Documents and Settings\user1\My Mail\personal.pst"
>
> strPSTFile = Right(strPSTFilePath, Len(strPSTFilePath) -
> InStrRev(strPSTFilePath, "\"))
> WScript.Echo strPSTFile
>
> ' alternatively, you can use Mid:
>
> strPSTFile = Mid(strPSTFilePath, InStrRev(strPSTFilePath, "\") + 1)
> WScript.Echo strPSTFile
>
> --
> torgeir
> Microsoft MVP Scripting and WMI, Porsgrunn Norway
> Administration scripting examples and an ONLINE version of the 1328 page
> Scripting Guide: http://www.microsoft.com/technet/scriptcenter
>
>



Re: InStr function not working by Tom

Tom
Tue Sep 16 14:52:28 CDT 2003


"Steve" <stephen.d.powers@wellsfargo.com> wrote in message
news:01fc01c37c81$38550ff0$a401280a@phx.gbl...
> Help!
> I have a script here that will not work correctly
> according to the InStrRev function rules. When it runs,
> the file path comes out really weird. For example, the
> path: "C:\Documents and Settings\user1\My
> Mail\personal.pst" is coming back "gs\user1\my
> mail\personal.pst" instead of just displaying the file
> name "personal.pst" like it should. Can someone please
> take a look? If you need the rest of the code, let me
> know. Basically what I have is a list of file path names
> in lstPSTList and I'm trying to trunkate the whole path so
> I just get the file name.
>
> strKeys = lstPSTList.Keys
> For intPST = 0 To lstPSTList.Count - 1
> strPSTFilePath = lstPSTList.Item(strKeys(intPST))
> strPSTFile = Right(strPSTFilePath, InStrRev
> (strPSTFilePath, "\"))
> MsgBox strPSTFile
> Next
>


This used to catch me out too.
InStrRev gives you the position from the left.
You are getting the wrong end of the string.

strPSTFile = MID(strPSTFilePath, InStrRev (strPSTFilePath, "\") + 1)

or

strPSTFile = Right(strPSTFile, Len(strPSTFile) - InStrRev(strPSTFile, "\"))


HTH







Re: InStr function not working by Steve

Steve
Tue Sep 16 17:01:05 CDT 2003

Ah, I see what I missed. Too many hours, not enough sleep
I guess. Thanks for your help!


>-----Original Message-----
>Steve wrote:
>
>> Basically what I have is a list of file path names
>> in lstPSTList and I'm trying to trunkate the whole path
so
>> I just get the file name.
>>
>> strKeys = lstPSTList.Keys
>> For intPST = 0 To lstPSTList.Count - 1
>> strPSTFilePath = lstPSTList.Item(strKeys(intPST))
>> strPSTFile = Right(strPSTFilePath, InStrRev
>> (strPSTFilePath, "\"))
>> MsgBox strPSTFile
>> Next
>
>Hi
>
>There is nothing wrong with the InStrRev function, you
just use the Right
>function incorrectly.
>
>This works better:
>
>strPSTFilePath = "C:\Documents and Settings\user1\My
Mail\personal.pst"
>
>strPSTFile = Right(strPSTFilePath, Len(strPSTFilePath) -
>InStrRev(strPSTFilePath, "\"))
>WScript.Echo strPSTFile
>
>' alternatively, you can use Mid:
>
>strPSTFile = Mid(strPSTFilePath, InStrRev
(strPSTFilePath, "\") + 1)
>WScript.Echo strPSTFile
>
>--
>torgeir
>Microsoft MVP Scripting and WMI, Porsgrunn Norway
>Administration scripting examples and an ONLINE version
of the 1328 page
>Scripting Guide:
http://www.microsoft.com/technet/scriptcenter
>
>
>.
>

Re: InStr function not working by Steve

Steve
Tue Sep 16 17:03:00 CDT 2003

Thanks for the post Tom. I figured I was missing
something else in this.


>-----Original Message-----
>
>"Steve" <stephen.d.powers@wellsfargo.com> wrote in message
>news:01fc01c37c81$38550ff0$a401280a@phx.gbl...
>> Help!
>> I have a script here that will not work correctly
>> according to the InStrRev function rules. When it runs,
>> the file path comes out really weird. For example, the
>> path: "C:\Documents and Settings\user1\My
>> Mail\personal.pst" is coming back "gs\user1\my
>> mail\personal.pst" instead of just displaying the file
>> name "personal.pst" like it should. Can someone please
>> take a look? If you need the rest of the code, let me
>> know. Basically what I have is a list of file path
names
>> in lstPSTList and I'm trying to trunkate the whole path
so
>> I just get the file name.
>>
>> strKeys = lstPSTList.Keys
>> For intPST = 0 To lstPSTList.Count - 1
>> strPSTFilePath = lstPSTList.Item(strKeys(intPST))
>> strPSTFile = Right(strPSTFilePath, InStrRev
>> (strPSTFilePath, "\"))
>> MsgBox strPSTFile
>> Next
>>
>
>
>This used to catch me out too.
>InStrRev gives you the position from the left.
>You are getting the wrong end of the string.
>
>strPSTFile = MID(strPSTFilePath, InStrRev
(strPSTFilePath, "\") + 1)
>
>or
>
>strPSTFile = Right(strPSTFile, Len(strPSTFile) - InStrRev
(strPSTFile, "\"))
>
>
>HTH
>
>
>
>
>
>
>.
>

Re: InStr function not working by Steve

Steve
Tue Sep 16 17:02:21 CDT 2003

Wow, I've never seen this before. I'll have to play with
it a bit and see how it works. The only problem is
getting the extra "\" & in the string. Thanks for the
help!


>-----Original Message-----
>I'm partial to
>strPSTFilePath = "\" & "C:\Documents and Settings\user1\My
>Mail\personal.pst"
>aSplit = Split(strPSTFilePath, "\")
>strPSTFile = aSplit(UBound(aSplit))
>
>Ray at work
>
>
>"Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com>
wrote in message
>news:3F675D2B.8683404D@hydro.com...
>> Steve wrote:
>>
>> > Basically what I have is a list of file path names
>> > in lstPSTList and I'm trying to trunkate the whole
path so
>> > I just get the file name.
>> >
>> > strKeys = lstPSTList.Keys
>> > For intPST = 0 To lstPSTList.Count - 1
>> > strPSTFilePath = lstPSTList.Item(strKeys(intPST))
>> > strPSTFile = Right(strPSTFilePath, InStrRev
>> > (strPSTFilePath, "\"))
>> > MsgBox strPSTFile
>> > Next
>>
>> Hi
>>
>> There is nothing wrong with the InStrRev function, you
just use the Right
>> function incorrectly.
>>
>> This works better:
>>
>> strPSTFilePath = "C:\Documents and Settings\user1\My
Mail\personal.pst"
>>
>> strPSTFile = Right(strPSTFilePath, Len(strPSTFilePath) -
>> InStrRev(strPSTFilePath, "\"))
>> WScript.Echo strPSTFile
>>
>> ' alternatively, you can use Mid:
>>
>> strPSTFile = Mid(strPSTFilePath, InStrRev
(strPSTFilePath, "\") + 1)
>> WScript.Echo strPSTFile
>>
>> --
>> torgeir
>> Microsoft MVP Scripting and WMI, Porsgrunn Norway
>> Administration scripting examples and an ONLINE version
of the 1328 page
>> Scripting Guide:
http://www.microsoft.com/technet/scriptcenter
>>
>>
>
>
>.
>

Re: InStr function not working by Ray

Ray
Wed Sep 17 07:47:55 CDT 2003

Torgeir's is probably more efficient though. I just like to to [over]use
the split function. :]

Ray at work

"Steve" <stephen.d.powers@wellsfargo.com> wrote in message
news:049b01c37c9e$33ae3e00$a401280a@phx.gbl...
> Wow, I've never seen this before. I'll have to play with
> it a bit and see how it works. The only problem is
> getting the extra "\" & in the string. Thanks for the
> help!