Solved

Pulling a file extension

Posted on 2009-07-05
3
264 Views
Last Modified: 2012-05-07
In c# what is an easy way to find a file extension.

My current way is kinda messy, and is very easy for the user to mess up.

The exact thing required is for the program to go forward one file, and look at a file of extension *.F*  where the second star is a number 4-10

Any Suggestions?
0
Comment
Question by:cotj73
3 Comments
 
LVL 9

Accepted Solution

by:
Rahul Goel ITIL earned 175 total points
ID: 24782526
You can use RegEx to achieve the same.
0
 
LVL 1

Assisted Solution

by:vaibhav_dw
vaibhav_dw earned 175 total points
ID: 24782547
Hi

Are you trying to extract the extension from the filename as the string or you have the filestream?

If you have just the filename as the string then you can traverse the string backwords till the period(.) and then traverse extactly 3 characters to get the extension. This is simply playing with the string.

Could you please tell exactly what do you have as a file so that I can help you out.

0
 
LVL 7

Assisted Solution

by:Raghu Mutalikdesai
Raghu Mutalikdesai earned 150 total points
ID: 24783299
// path is your file path
System.IO.Path.GetExtension(path)
System.IO.Path.GetFileNameWithoutExtension(path)
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question