473,698 Members | 2,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

< Split File from File+Path >

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
4 16714
Look at "Path" class. It is quite powerfull

José

"Carsten Kraft" <Ca***********@ RR-Software.de> wrote in message
news:%2******** ********@TK2MSF TNGP10.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
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******** ********@TK2MSF TNGP10.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
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******** ********@TK2MSF TNGP10.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
Try:

string sFile = "C:\\DIR\\SUBDI R\\TEST.XML";
sFile = sFile.Substring (sFile.LastInde xOf("\\")+1);

Steve

"Carsten Kraft" <Ca***********@ RR-Software.de> wrote in message
news:%2******** ********@TK2MSF TNGP10.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3103
by: Simon | last post by:
I wonder if someone can help with this - I 'm creating an IISVirtualDirectory, and setting its Path property to the physical path I want to reference. This works fine when I have a standard file path - 'C:/Test' - however I sometimes have a UNC path - '//remoteComputer/Test' - and IIS appears to choke when it's given that. So, is there any way of translating a UNC path to the physical path on the remote computer? ie: Translating '...
5
11046
by: David Webb | last post by:
The problem started when the Working Folder for a project was somehow set to the folder of another project. I set the correct working folder in VSS and deleted the .vbproj files that had been created in the wrong folder on the hard drive. Before I discovered these files, .NET kept trying to create a new project with _1 following the project name. Deleting those files corrected that problem. I deleted the Virtual Directory, rebooted, and...
2
1726
by: Teis Draiby | last post by:
(Using C#) Question 1: Is there an easy build-in support for determining wether a given file path is 1) A valid file path (Only legal characters) 2) The file exists 3) The path exists
7
6376
by: TLM | last post by:
I am trying to build a web application that will contain links to files on a users local computer. I am assuming that the files will be in a known location and can display in a browser window. I have my ASP.NET application building links along the lines of file://c:/<path to file>
10
2793
by: darrel | last post by:
I have an input type="file" field that I am using to accept a file upload. This works, but I'm having problems with the filename property. In firefox, this: MyInputField.postedfile.filename returns the filename...and just the filename. Which is what I want. In IE, however, this returns the ENTIRE local user's system path to the file
5
8620
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file". Same file path containing special characters works fine in one machine, but doesn't work in other. I am using following API function to get short file path. Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As
2
5256
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 in the text box of File control. But in the code behind when I try to get the FullFile path using file1.PostedFile.FilePath it is not giving the full path (c:\test\test.pdf). Instead it is giving only file name (test.pdf). If i try to do this on...
3
3373
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt, &gt ,&ltCompany&gt to display '<', '>' and '<Company>' respectively. But is there any freeware code available which could implement the above functionality without having to use &gt,&lt and such stuff???
10
4440
by: Andrew Backer | last post by:
I have a few file:///c:/windows/somewhere style uris that I need to convert to the actual physical path. I am hoping there is a built in way to handle this. I know I can do some text replacing and get the path, at least in this case, but I'd rather not do that if there is something that already does it more robustly. // Andrew
4
1653
by: Coolfusion | last post by:
Hi there, I want the programe to search for the shortcut exe file on the desktop and display the file path of the file. To obtain the file path manually, right-click the shortcut exe file and go to properties and the path is under the row called Target. Currently the code i wrote cannot display the path. Can you tell me wat is the problem. I m currently using vb.net 2003. Thanks in advance Private Sub cmdGet_Path_Click(ByVal sender...
0
8609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9169
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9030
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8871
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7738
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.