473,396 Members | 2,106 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,396 software developers and data experts.

Extract file name

I got a string. eg.

C:\Temp\Documents\MyDoc.doc

How do I get the name of the document only?
ie. MyDoc.doc
Jul 27 '06 #1
4 18614


Alan T wrote:
I got a string. eg.

C:\Temp\Documents\MyDoc.doc

How do I get the name of the document only?
ie. MyDoc.doc

Try this:

using System.IO;

FileInfo fileInfo = new FileInfo(fileName);
string nameWithoutPath=fileInfo.Name.
Jul 27 '06 #2
Jianwei,

That's a bit much, actually. I would recommend using the static
GetFileName method on the Path class in the System.IO namespace.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jianwei Sun" <js***********@gmail.comwrote in message
news:eE**************@TK2MSFTNGP05.phx.gbl...
>

Alan T wrote:
>I got a string. eg.

C:\Temp\Documents\MyDoc.doc

How do I get the name of the document only?
ie. MyDoc.doc

Try this:

using System.IO;

FileInfo fileInfo = new FileInfo(fileName);
string nameWithoutPath=fileInfo.Name.


Jul 27 '06 #3
Thanks, it works.

After I got the name, how do I get rid of the extension ?

Eg.
MyDoc.doc to MyDoc

"Jianwei Sun" <js***********@gmail.comwrote in message
news:eE**************@TK2MSFTNGP05.phx.gbl...
>

Alan T wrote:
>I got a string. eg.

C:\Temp\Documents\MyDoc.doc

How do I get the name of the document only?
ie. MyDoc.doc

Try this:

using System.IO;

FileInfo fileInfo = new FileInfo(fileName);
string nameWithoutPath=fileInfo.Name.


Jul 27 '06 #4
Alan,

You can pass the file name to the static GetFileNameWithoutExtension
method on the Path class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Alan T" <al*************@yahoo.com.auwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Thanks, it works.

After I got the name, how do I get rid of the extension ?

Eg.
MyDoc.doc to MyDoc

"Jianwei Sun" <js***********@gmail.comwrote in message
news:eE**************@TK2MSFTNGP05.phx.gbl...
>>

Alan T wrote:
>>I got a string. eg.

C:\Temp\Documents\MyDoc.doc

How do I get the name of the document only?
ie. MyDoc.doc

Try this:

using System.IO;

FileInfo fileInfo = new FileInfo(fileName);
string nameWithoutPath=fileInfo.Name.



Jul 27 '06 #5

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

Similar topics

5
by: Jane Doe | last post by:
Hi I took a quick look in the archives, but didn't find an answer to this one. I'd like to display a list of HTML files in a directory, showing the author's name between brackets after the...
3
by: Phong Ho | last post by:
Hi everyone, I try to write a simple web crawler. It has to do the following: 1) Open an URL and retrieve a HTML file. 2) Extract news headlines from the HTML file 3) Put the headlines into a...
10
by: Robert Schultz | last post by:
I have a C/C++ file that I simply want to 'extract' a function from. Something like: extract <function name> <c or cpp file> I want it to return from the beginning of the function, to the end. ...
2
by: RichardHatcher.com | last post by:
I am writing C code using xpath to extract some data from a XML document. The file uses namespaces, but the name spaces are all listed in the root node of the file as attributes. I want to...
7
by: erikcw | last post by:
Hi all, I'm trying to extract zip file (containing an xml file) from an email so I can process it. But I'm running up against some brick walls. I've been googling and reading all afternoon, and...
0
by: napolpie | last post by:
DISCUSSION IN USER nappie writes: Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file. This file is long file and it's composed by...
1
by: Petra Meier | last post by:
Hi, I hope this is a proper place to post :) This is my XML file: <?xml version="1.0" encoding="utf-8"?> <foo> <address>a lot of tags and text</address> <hubid>a lot of tags and text</hubid>...
3
by: learningvbnet | last post by:
Hi, I am trying to extract zipped files using Winzip in my VB.net application and I ran into 2 stone walls. 1. How do you handle file names with spaces. See psiProcess.Arguments For...
5
by: Steve | last post by:
Hi all Does anybody please know a way to extract an Image from a pdf file and save it as a TIFF? I have used a scanner to scan documents which are then placed on a server, but I need to...
3
rizwan6feb
by: rizwan6feb | last post by:
I am trying to extract php code from a php file (php file also contains html, css and javascript code). I am using the following regex for this <\?*?\?> but this doesn't cater quotation marks...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
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...

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.