how to strip a string 
Author Message
 how to strip a string

Quote:

> I have a string c:\myfiles\thisdir\file.doc
> I need to get    file
> The right is always striped to the . then to the \
> The length of file varies.

Try these to separate the file and directory names:

Function FileName (ByVal Path As String) As String
    Dim Pos As Long, p As Long: Pos = 0
    If Path Like "[A-Za-z]:*" Then Pos = 2
    Do
        p = InStr(Pos + 1, Path, "/", 0)
        If p = 0 Then Exit Do
        Pos = p
    Loop
    Do
        p = InStr(Pos + 1, Path, "\", 0)
        If p = 0 Then Exit Do
        Pos = p
    Loop
    FileName = Mid$(Path, Pos + 1)
End Function

Function DirName (ByVal Path As String) As String
    Dim pos As Long, p As Long: Pos = 0
    If Path Like "[A-Za-z]:*" Then Pos = 2
    Do
        p = InStr(Pos + 1, Path, "/", 0)
        If p = 0 Then Exit Do
        Pos = p
    Loop
    Do
        p = InStr(Pos + 1, Path, "\", 0)
        If p = 0 Then Exit Do
        Pos = p
    Loop
    DirName = Left$(Path, Pos)
End Function

However, Win32 allows file names like "myfile.2001.02.28.doc". Do you
want "myfile.2001.02.28" or just "myfile"? What if there's an NTFS named
substream, as in "myfile.2001.02.28.doc:alternatestream"?

--

WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Tue, 16 Sep 2003 08:18:03 GMT  
 how to strip a string
An easy approach is to use the FileSystemObject, which has methods for
this.

Add a reference to "Microsoft Scripting Runtime" to your project, then
declare a variable As Scripting.FileSystemObject.




Quote:

> > I have a string c:\myfiles\thisdir\file.doc
> > I need to get    file
> > The right is always striped to the . then to the \
> > The length of file varies.

> Try these to separate the file and directory names:

> Function FileName (ByVal Path As String) As String
>     Dim Pos As Long, p As Long: Pos = 0
>     If Path Like "[A-Za-z]:*" Then Pos = 2
>     Do
>         p = InStr(Pos + 1, Path, "/", 0)
>         If p = 0 Then Exit Do
>         Pos = p
>     Loop
>     Do
>         p = InStr(Pos + 1, Path, "\", 0)
>         If p = 0 Then Exit Do
>         Pos = p
>     Loop
>     FileName = Mid$(Path, Pos + 1)
> End Function

> Function DirName (ByVal Path As String) As String
>     Dim pos As Long, p As Long: Pos = 0
>     If Path Like "[A-Za-z]:*" Then Pos = 2
>     Do
>         p = InStr(Pos + 1, Path, "/", 0)
>         If p = 0 Then Exit Do
>         Pos = p
>     Loop
>     Do
>         p = InStr(Pos + 1, Path, "\", 0)
>         If p = 0 Then Exit Do
>         Pos = p
>     Loop
>     DirName = Left$(Path, Pos)
> End Function

> However, Win32 allows file names like "myfile.2001.02.28.doc". Do you
> want "myfile.2001.02.28" or just "myfile"? What if there's an NTFS
named
> substream, as in "myfile.2001.02.28.doc:alternatestream"?

> --


<http://www.xenu.net/>

- Show quoted text -

Quote:
> WARNING: I cannot be held responsible for the above        They're
coming  to
> because  my cats have  apparently  learned to type.        take me
away, ha ha!



Wed, 17 Sep 2003 04:07:18 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. how to strip a string

2. Large file handling & replacing/stripping out strings.

3. Strip Spaces from string

4. Stripping vbCrLf from strings

5. Strip spaces from string

6. String.Trim does not strip

7. Need Regular Expression to strip non-numeric characters from string

8. stripping a string - Newbie

9. Pls Help Newbie: Stripping Strings of CR and LF

10. Help Newbie - String stripping...?

11. Strip Tab from String

12. HELP! Stripping NON ALPHA characters from a string

 

 
Powered by phpBB® Forum Software