473,411 Members | 1,995 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,411 software developers and data experts.

Filename from Full Path?

Is there a method anywhere for extracting just the filename part of a
full path name?

--Bruce

Nov 15 '05 #1
6 10486
Check out the Path class.

"Bruce Vander Werf" <br*****@hotmail.com> wrote in message
news:d4********************************@4ax.com...
Is there a method anywhere for extracting just the filename part of a
full path name?

--Bruce

Nov 15 '05 #2
Hi Bruce,

That is as simple as using SubString method:
// not tested code.
string filename = fullpath.Substring( fullpath.LastIndexOf("\\")+1);

fullpath is a string containing the full path of the file, take a look at
the Path class.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Bruce Vander Werf" <br*****@hotmail.com> wrote in message
news:d4********************************@4ax.com...
Is there a method anywhere for extracting just the filename part of a
full path name?

--Bruce

Nov 15 '05 #3
Much easier to simply do:

string filename = Path.GetFileName(fullpath);
"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
Hi Bruce,

That is as simple as using SubString method:
// not tested code.
string filename = fullpath.Substring( fullpath.LastIndexOf("\\")+1);

fullpath is a string containing the full path of the file, take a look at
the Path class.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Bruce Vander Werf" <br*****@hotmail.com> wrote in message
news:d4********************************@4ax.com...
Is there a method anywhere for extracting just the filename part of a
full path name?

--Bruce


Nov 15 '05 #4
Like Peter mentioned, the Path class is an easy way to do
it....

System.IO.Path p;

string s = Crypto.EncryptFile(FileName
(i));
string shortName = p.GetFileName(s);

The filename property of the fileinfo class (I think) will
give it to you as well..but I know the top one does.

Cheers,

Bill

-----Original Message-----
Is there a method anywhere for extracting just the filename part of afull path name?

--Bruce

.

Nov 15 '05 #5
William Ryan <do********@comcast.nospam.net> wrote:
Like Peter mentioned, the Path class is an easy way to do
it....

System.IO.Path p;

string s = Crypto.EncryptFile(FileName
(i));
string shortName = p.GetFileName(s);

The filename property of the fileinfo class (I think) will
give it to you as well..but I know the top one does.


Path.GetFileName is a static method, and cannot be called with a
reference. This is good, as it means you don't end up with a variable
there for no good reason, and a call which looks like it's an instance
method.

(This is one area where C# wins over Java, although with suitable
settings in some IDEs such as Eclipse, you can turn it into a
warning/error in Java, too.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #6
Thanks, the Path class is exactly what I was looking for!

I am continually amazed at the richness of the FCL.

--Bruce
Nov 15 '05 #7

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

Similar topics

5
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...
2
by: Xam | last post by:
Hello everybody Do you know of a javascript routine that can warn if there are any pre-defined invalid chars in the filename of an INPUT file box before it is submitted with the submit button. ...
2
by: Ronny Sigo | last post by:
Hello all, I have made a form which takes input from the user (things like name,adress, reference number and so on). After filling in the form, the user presses a button. The program then takes...
2
by: Csharper95 | last post by:
I want to get the file name and path from a SaveFileDialog (for a 'save as' operation) after the user has saved the information under a new file name (and presumably under a new path) ? I want...
1
by: Andres Romero | last post by:
Using the FielDialog class and it's FileName propertie I can know the Path and file name selected by the user, but now I need to know only the file name without the full path (eg....
3
by: Darrel | last post by:
using Request.FilePath will return the entire file path: directory/directory/myfile.aspx Is there a built function in ASP.net to grab just the filename (myfile.aspx) or do I need to write...
2
by: Sridhar | last post by:
Hi, I have a web form where it has a <input type=file id=file1> control. I have an Upload button to upload the file. WHen I click on browse and select one file, it is showing the full file path...
3
by: smay | last post by:
I'm building a small app that is launched by right-clicking on an XML file and choosing "Open With...". Ugly, I know, but I can't associate .xml with my app. Anyway, once the app is launched, how...
3
by: =?Utf-8?B?RGV2b24=?= | last post by:
Is it possible to retrieve a proper/invariant file or directory name using a lowercase full path string without having to resort to a call to GetDirectories()/GetFiles() using the...
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
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
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.