By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,060 Members | 1,906 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,060 IT Pros & Developers. It's quick & easy.

< Split File from File+Path >

P: n/a
Hello Newsgroup,

I am searching for function which returns me filename from a string that has
the file + filepath.
( string sFile = "C:\DIR\SUBDIR\TEST.XML" => TEST.XML)

Is there a functional class for this or what have I to do?

Thanks alot ...
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Look at "Path" class. It is quite powerfull

Josť

"Carsten Kraft" <Ca***********@RR-Software.de> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello Newsgroup,

I am searching for function which returns me filename from a string that has the file + filepath.
( string sFile = "C:\DIR\SUBDIR\TEST.XML" => TEST.XML)

Is there a functional class for this or what have I to do?

Thanks alot ...

Nov 15 '05 #2

P: n/a
there's a few ways you can do it...

I like to take advantage of the split method in the string object.

string getFileName ( string szPath )
{
string [] szTokens = szPath.Split('\\');
return szTokens[ szTokens.Length - 1 ];
}

To use, you'd say:

string szFileName = getFileName ( szPath );

hope that helps.
Dan.

"Carsten Kraft" <Ca***********@RR-Software.de> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello Newsgroup,

I am searching for function which returns me filename from a string that has
the file + filepath.
( string sFile = "C:\DIR\SUBDIR\TEST.XML" => TEST.XML)

Is there a functional class for this or what have I to do?

Thanks alot ...

Nov 15 '05 #3

P: n/a
Hi Carsten,

Take a look at the GetFileName method on the System.IO.Path class.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Carsten Kraft" <Ca***********@RR-Software.de> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello Newsgroup,

I am searching for function which returns me filename from a string that has the file + filepath.
( string sFile = "C:\DIR\SUBDIR\TEST.XML" => TEST.XML)

Is there a functional class for this or what have I to do?

Thanks alot ...


Nov 15 '05 #4

P: n/a
Try:

string sFile = "C:\\DIR\\SUBDIR\\TEST.XML";
sFile = sFile.Substring(sFile.LastIndexOf("\\")+1);

Steve

"Carsten Kraft" <Ca***********@RR-Software.de> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
| Hello Newsgroup,
|
| I am searching for function which returns me filename from a string that
has
| the file + filepath.
| ( string sFile = "C:\DIR\SUBDIR\TEST.XML" => TEST.XML)
|
| Is there a functional class for this or what have I to do?
|
| Thanks alot ...
|
|
Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.