Changing file extensions

  • Thread starter Thread starter Claire
  • Start date Start date
C

Claire

There used to be a nice api call to change a file extension. Is there a
class that will do this in c# .net?
The FileInfo class will return some information about a queried file. Yes I
can query the whole file path/name and the extension, but I can't query the
raw filename without its extension and I'd like to avoid having to write a
parser if possible.
Would it be safe to do something as simple as chopping the final
(extension.Length) characters from the end of the full filename then re-add
the new one (omg what fudge) ?
 
Claire,

The GetFileNameWithoutExtension method of the System.IO.Path class is
probably what you want for this.

HTH,
Nicole
 
Does File.Move solve your problem?
Check also Path.GetFileNameWithoutExtension, Path.GetExtension and
Path.GetFileName methods.
Related Directory methods: Name and Extension.

HTH
Alex
 
There used to be a nice api call to change a file extension. Is there a
class that will do this in c# .net?

Path.ChangeExtension (in the System.IO namespace)

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top