James
Fri Jul 22 10:09:30 CDT 2005
Use could also use the 'Scripting.FileSystemObject' to do the work for you:
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
path = "C:\mydir\mysubdir\myfile.ext"
MsgBox FSO.GetFileName(path)
"Jo Winchester" <JoWinchester@discussions.microsoft.com> wrote in message
news:C89C7498-E972-49BF-B6F8-D4213DA56098@microsoft.com...
> Thanks a lot for your reply - but I have looked at this again and found a
> simpler way to extract the file name. This is an example of the code I
have
> used.
>
> path = _ "C:\mydir\mysubdir\myfile.ext"
> posA = InStr(1, path, "\") +1
> posB = InStrRev(path, "\")
> MsgBox Mid(path, posA, posB - posA)
>
>
> "Roland Hall" wrote:
>
> > "Jo Winchester" wrote in message
> > news:E57B28AA-7E65-4F09-BE0C-481E4689555E@microsoft.com...
> > :I am automating FTP tranfers, and need to read a log file and extract
the
> > : name of the files transferred.
> > :
> > : An example line of text is:
> > : 150 Opening ASCII mode data connection for testfile.txt(0 bytes).
> > :
> > : All that I want to extract from the line is "testfile.txt".
> > :
> > : The following code works - (the wscript.echo is the relevant line):
> > : If Left (strline, 3) = "150" then
> > : TestString = strline
> > : TestArray = Split(TestString , " ",-1, 1)
> > : wscript.echo
> > : Left(TestArray(7),InStr(TestArray(7),"(")-1)
> > : Else
> > : 'script not included in example
> > : End If
> > :
> > : However, if the file name is more than one word long
> > :
> > : 150 Opening ASCII mode data connection for new testfile.txt(0 bytes).
> > :
> > : The script fails.
> > :
> > : Can anyone suggest a better way to extract the file name?
> >
> > That's probably because you're splitting by spaces and a file name with
a
> > space gets put into two different elements in your array. Please show a
> > line of data, at least out to element 9.
> >
> > Also, these are all defaults:
> >
> > , " ",-1, 1)
> >
> > in...
> > TestArray = Split(TestString , " ",-1, 1)
> > You can just use:
> > TestArray = Split(TestString)
> >
> > You can also eliminate this line:
> > : TestString = strline
> >
> > Just change the next line to:
> > TestArray = Split(strline)
> >
> > --
> > Roland Hall
> > /* This information is distributed in the hope that it will be useful,
but
> > without any warranty; without even the implied warranty of
merchantability
> > or fitness for a particular purpose. */
> > Technet Script Center -
http://www.microsoft.com/technet/scriptcenter/
> > WSH 5.6 Documentation -
http://msdn.microsoft.com/downloads/list/webdev.asp
> > MSDN Library -
http://msdn.microsoft.com/library/default.asp
> >
> >
> >