One of my friend once asked how to get file name from a path. There're actually a lot of ways to do it. I'll try a simple one, using Split and UBound function.
e.g. the path is C:\Test\DeeperPath\EvenDeeperPath\Test.txt
and we're going to get the file name, i.e. Text.txt
The name of the controls:
textbox : Text1, containing the path
Some things we have to know:
1. To split the path into array: Split(Text1.Text, "\")
We'll get array of string:
Split(Text1.Text, "\")(0) = C:
Split(Text1.Text, "\")(1) = Test
Split(Text1.Text, "\")(2) = DeeperPath
Split(Text1.Text, "\")(3) = EvenDeeperPath
Split(Text1.Text, "\")(4) = Test.txt
2. To get upper bound of an array: UBound(array)
So, to get the file name from a path, we just need a line of code:
Split(Text1.Text, "\")(UBound(Split(Text1.Text, "\")))
The result will be: Test.txt
Wednesday, April 15, 2009
You may be intersted in
Related Posts
Updating Table Containing Xml Column via LinkedServer
If you are trying to update a table containing XML column via Linked Server in SQL Server, and you are not able to, you are not alone. There...
hi i am Naveen soni new vb developer give me your gmail id for chat my gmail id is jaihons@gmail.com
ReplyDeletei dont understand this code how it work i founded manny codes on net but not any working i have manny projects to work in vb can you help me for making or solving my problems please reply me?
Hi Naveen, I can not help you making your projects. However, if you have any enquiry, feel free to tell your problem here ^^
ReplyDelete