Hi,
Using the code below I can extract the filename from a path but I would like
to know how to get just the path too.
So if the full path is "C:\A Long Time Ago\In A Galaxy\Far Far
Away\SomeFilename.txt"
The filename is: SomeFilename.txt
The path only is: C:\A Long Time Ago\In A Galaxy\Far Far Away\
I know there's other methods of getting the filename only, path only etc.
that are new to VB.NET but they involve using the FileInfo/DirectoryInfo
classes and for this I prefer to use the InStrRev/Trim method.
Thanks,
Paul
Dim i As Integer
Dim sFilename As String
Dim file As String = "C:\A Long Time Ago\In A Galaxy\Far Far
Away\SomeFilename.txt"
i = InStrRev(file.Trim, "\")
If i = 0 Then
'No path found, only filename
sFilename = file.Trim
Else
'Assign filename only to variable
sFilename = Right(file.Trim, Len(file.Trim) - i)
End If
MsgBox(sFilename) 5 12455
You can use virtually the same code...just change to use the MID function,
retunring the 1st character through the character before the first \ from
the end. 'Assign path only to variable sPath = Mid(file.Trim, 1, i-1)
"Paul" <me@home.com> wrote in message
news:g5********************@pipex.net... Hi,
Using the code below I can extract the filename from a path but I would like to know how to get just the path too. So if the full path is "C:\A Long Time Ago\In A Galaxy\Far Far Away\SomeFilename.txt" The filename is: SomeFilename.txt The path only is: C:\A Long Time Ago\In A Galaxy\Far Far Away\
I know there's other methods of getting the filename only, path only etc. that are new to VB.NET but they involve using the FileInfo/DirectoryInfo classes and for this I prefer to use the InStrRev/Trim method.
Thanks, Paul
Dim i As Integer Dim sFilename As String Dim file As String = "C:\A Long Time Ago\In A Galaxy\Far Far Away\SomeFilename.txt"
i = InStrRev(file.Trim, "\") If i = 0 Then 'No path found, only filename sFilename = file.Trim Else 'Assign filename only to variable sFilename = Right(file.Trim, Len(file.Trim) - i) End If
MsgBox(sFilename)
Thanks Lawrence, that did the job nicely.
"Lawrence J. Rizzo" <lj********@adelphia.net> wrote in message
news:Kr********************@adelphia.com... You can use virtually the same code...just change to use the MID function, retunring the 1st character through the character before the first \ from the end.
'Assign path only to variable sPath = Mid(file.Trim, 1, i-1) "Paul" <me@home.com> wrote in message news:g5********************@pipex.net... Hi,
Using the code below I can extract the filename from a path but I would like to know how to get just the path too. So if the full path is "C:\A Long Time Ago\In A Galaxy\Far Far Away\SomeFilename.txt" The filename is: SomeFilename.txt The path only is: C:\A Long Time Ago\In A Galaxy\Far Far Away\
I know there's other methods of getting the filename only, path only etc. that are new to VB.NET but they involve using the FileInfo/DirectoryInfo classes and for this I prefer to use the InStrRev/Trim method.
Thanks, Paul
Dim i As Integer Dim sFilename As String Dim file As String = "C:\A Long Time Ago\In A Galaxy\Far Far Away\SomeFilename.txt"
i = InStrRev(file.Trim, "\") If i = 0 Then 'No path found, only filename sFilename = file.Trim Else 'Assign filename only to variable sFilename = Right(file.Trim, Len(file.Trim) - i) End If
MsgBox(sFilename)
Or you could use the shared methods of the Path class
Thanks Chris and Cor
"Cor Ligthert" <no************@planet.nl> wrote in message
news:Oe**************@TK2MSFTNGP12.phx.gbl... Paul,
For that is the path class. http://msdn.microsoft.com/library/de...mberstopic.asp
I give you the member page the class page is for this in my opinion a little bit confusing.
I hope this helps,
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: mtech1 |
last post by:
Access 2000
I need to extract just the filename from a path.
Ex: path is- c:\MyApp\Sub\MyApp.exe
I need to capture just the file name regardless of the size of it's
name. For the above...
|
by: Kristoffer Persson |
last post by:
It's probably very simple... I would like to know if there is a function
similar to ExtractFileName() (I've used it in Delphi), which returns only
the file name from the full path, e.g....
|
by: Scott Reynolds |
last post by:
Hello!
Could someone please provide me a sample, how to extract filename from url?
http://www.mydomain.com/eng/Default.aspx -> Default.aspx
Thanks
Scott
|
by: steve |
last post by:
How can someone extract the file name and file path from a complete path?
ex: c:\mydir\subdir\temp\myfile.txt
will give:
path = c:\mydir\subdir\temp
filename = myfile.txt
TIA
|
by: Paul |
last post by:
Hi,
Using the code below I can extract the filename from a path but I would like
to know how to get just the path too.
So if the full path is "C:\A Long Time Ago\In A Galaxy\Far Far...
| |
by: savvy |
last post by:
I am developing a Recruitment Agency Website
I am using MS SQL Server in which I have a table called CV_Details
which stores all the details of different Job Seekers. I have stored
all the Word...
|
by: SteveB |
last post by:
I have posted this question in the Visual Basic 2005 and Visual
Basic .Net 2005 discussion groups, also.
Hi. I am developing an application/web page with VB.Net that will
populate a SQL...
|
by: Steve |
last post by:
Hi all
Does anybody please know a way to extract an Image from a pdf file and save
it as a TIFF?
I have used a scanner to scan documents which are then placed on a server,
but I need to...
|
by: Paul Mc |
last post by:
Hi all,
It's a little late in the day for me so please forgive as i need my bed.!!
The issue is i need to open a word doc (say "c:\temp.doc) and paste into it, but i only can work out how...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |