Alex Rivera | Logout

Add file extension to extension-less file

Asked 2010-10-01T16:11:15.617
18

I'm trying to add an extension to a file that is selected in an OpenFileDialog in my C# app. I'm having difficulty with files that don't already have an extension.

While I haven't tested the following method on files with an extension, I know that it doesn't work for files without an extension (which is really what I want to work with here).

string tPath = videoPath + videoName;
string tPath2 = Path.ChangeExtension(tPath, ".yuv");

tPath2 will reflect to header change, but it seems not to affect the file itself, only the string returned by the ChangeExtension method. I'd just go ahead and copy the file into a new one with the appropriate name and extension, but we're talking about huge, uncompressed HD video files. Is there a way to utilize tPath2 with a File or FileInfo object that I'm missing?

I appreciate any assistance that anyone can give me here. Thanks.

c#
Edit
Report

1 Answer

3

You need to actually call FileInfo.MoveTo to rename the file. A file rename, on the same physical drive, is usually a fast operation, so it doesn't really matter that the file is huge.

answered 2010-10-01T16:13:59.890

Your Answer