473,836 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10507
Check out the Path class.

"Bruce Vander Werf" <br*****@hotmai l.com> wrote in message
news:d4******** *************** *********@4ax.c om...
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.Substr ing( fullpath.LastIn dexOf("\\")+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*****@hotmai l.com> wrote in message
news:d4******** *************** *********@4ax.c om...
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.GetFileNam e(fullpath);
"Ignacio Machin" <ignacio.mach in AT dot.state.fl.us > wrote in message
news:uU******** ******@TK2MSFTN GP10.phx.gbl...
Hi Bruce,

That is as simple as using SubString method:
// not tested code.
string filename = fullpath.Substr ing( fullpath.LastIn dexOf("\\")+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*****@hotmai l.com> wrote in message
news:d4******** *************** *********@4ax.c om...
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.EncryptF ile(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********@com cast.nospam.net > wrote:
Like Peter mentioned, the Path class is an easy way to do
it....

System.IO.Path p;

string s = Crypto.EncryptF ile(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.GetFileNam e 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.co m>
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
12488
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 Away\SomeFilename.txt" The filename is: SomeFilename.txt The path only is: C:\A Long Time Ago\In A Galaxy\Far Far Away\ I know there's other methods of getting the filename only, path only etc.
2
2912
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. The process would be: a) User clicks the INPUT File's Browse button to select the file from their computer.
2
2333
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 all the values out of the controls, opens MS Word and uses these values to compose a letter with all the data pre-filled in. Now my question is : Can I make a variable, containing some text which comes out of the controls of the form and use this...
2
50407
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 to display the new file name and path in the Form.text Title. So how do I go about getting the info ? Heres my code:
1
7735
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. "C:\folder1\folder2\filename.txt", I just need the "filename.txt"), how can I do it?
3
3537
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 some string manipulation functions to grab it out of the filepath? -Darrel
2
5264
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
1145
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 can I get the full path to the XML file that was opened?
3
4871
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 directory/filename as the search string? While Path, FileInfo, and DirectoryInfo all store the path information, they use the path case passed to them, so passing a lowercase path to Path.GetFullPath() will return a lowercase full path. TIA
0
9825
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9672
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,...
1
10601
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7794
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
6981
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
5652
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4460
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
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.