473,394 Members | 1,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to extract file name and path separately

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
Nov 21 '05 #1
5 21951
dim sFile as String = "c:\mydir\subdir\temp\myfile.txt"
dim oFileInfo as New System.IO.FileInfo(sFile)
debug.WriteLine(oFileInfo.DirectoryName)
debug.WriteLine(oFileInfo.Name)

hope this helps..
Imran.

"steve" <noemail.@try.com> wrote in message
news:_M**********************@wagner.videotron.net ...
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

Nov 21 '05 #2

"steve" <noemail.@try.com> wrote in message
news:_M**********************@wagner.videotron.net ...
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


In addition to Imran's response, check out the System.IO.Path class.
Nov 21 '05 #3
Easiest way is to use a FileInfo object, part of System.IO

Dim filePath As String = "c:\mydir\subdir\temp\myfile.txt"
Dim checkFileInfo As New System.IO.FileInfo(filePath)

Dim path as String = checkFileInfo.DirectoryName
Dim fileName as String = checkFileInfo.Name

"steve" <noemail.@try.com> wrote in message
news:_M**********************@wagner.videotron.net ...
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

Nov 21 '05 #4
I'm not sure which is faster but:
ipos = filepathAndName.LastIndexOf("\")
path = filepathAndName.Substring(0, ipos)
filename = filepathAndName.Substring(ipos + 1, filepathAndName.Length -
ipos - 1)

Steve
hope my math was right
"steve" <noemail.@try.com> wrote in message
news:_M**********************@wagner.videotron.net ...
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

Nov 21 '05 #5
* "steve" <noemail.@try.com> scripsit:
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


'System.IO.Path' -> Press F1 key.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
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...
39
by: Joe Laughlin | last post by:
If I have a character array with "/some/file/directory/file_name", are there any functions / libraries that I could use to separate the directory ("some/file/directory") from the file name...
5
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....
3
by: Bill | last post by:
Is there a method that will take a full path and filename as a parameter and return just the filename? I am currently using the following code but it is extremely slow for files on a DVD. for...
1
by: Miki Peric | last post by:
Which .Net function I should use to extract file name from URL/path?
4
by: Alan T | last post by:
I got a string. eg. C:\Temp\Documents\MyDoc.doc How do I get the name of the document only? ie. MyDoc.doc
3
by: aGSMITH | last post by:
Hello All, I have an exportfile .txt from robocopy utility and I would need to get file name path from the file and save it to file1.txt after get the filename value and save it to file2.txt ...
3
by: selvialagar | last post by:
Hi.............. I need to extract a textfile (.txt) file alone from the application startup path. That is I stored a text file in d:\text\inputfile.txt. The folder contains a text file.but i...
0
by: maheen khan | last post by:
basically i extracted some attributes of file(name, file type, path etc) present in a directory and listed them in a c++ file, now i want to extract the file path only so that i can use it as an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.