-
Aug 5th, 2010, 08:04 AM
#1
Thread Starter
Lively Member
[RESOLVED] trim path from filename
I am trying to trim the path from a filename. With the following code, it returns "My Documents" where I should be getting "Test.txt". if I change the 1 to a 4 I get what I'm looking for, but that's not going to work if I'm working with a file deeper into subdirectories.
I need it to display the name of the file regardless of location or file type. Any ideas?
Code:
Private Sub trimname()
Dim filelabel
split = current.Split("\")
filelabel = Trim(split(1))
Elbow1.ButtonText = filelabel
End Sub
Anyone who does not wonder, is either omnipotent or a fool.
Amerigoware <<<My Projects
-
Aug 5th, 2010, 08:07 AM
#2
Re: trim path from filename
Use System.IO.FileInfo and get the fileName from there
Code:
Dim MyFileInfo As New System.IO.FileInfo("YOUR FULL PATH")
MyFileInfo.FileName will give the name.
-
Aug 5th, 2010, 08:08 AM
#3
Frenzied Member
Re: trim path from filename
Use the FileInfo class:
vb Code:
Dim filepath as string = "C:\blah\blah2\blah3\blah4\test.txt"
Dim FI as new IO.FileInfo(filepath)
Dim NameWithoutPath as String = FI.Name
Justin
-
Aug 5th, 2010, 08:08 AM
#4
Re: trim path from filename
try this:
Code:
Dim fullPath as string = "c:\xyz\dcf\test.txt"
Dim fileName as string = IO.Path.GetFileName(fullPath)
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Aug 5th, 2010, 09:22 AM
#5
Re: trim path from filename
Originally Posted by stanav
try this:
Code:
Dim fullPath as string = "c:\xyz\dcf\test.txt"
Dim fileName as string = IO.Path.GetFileName(fullPath)
Agreed.
-
Aug 5th, 2010, 12:46 PM
#6
Thread Starter
Lively Member
Re: RESOLVED>> trim path from filename
Thank you very much, guys.
Anyone who does not wonder, is either omnipotent or a fool.
Amerigoware <<<My Projects
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|