469,883 Members | 1,119 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,883 developers. It's quick & easy.

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 10290
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Paul | last post: by
3 posts views Thread by smay | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.