0

I have the desire to add file extensions and not change the old extension. Suppose file.jpg becomes file.jpg.bmp is that possible ?

string filename;
                string[] file = Directory.GetFiles(folder_path);
                foreach (string myfile in file)
                {
                    filename = Path.ChangeExtension(myfile, ".bmp");
                    System.IO.File.Move(myfile, filename);
                }

my code only changes extensions, for example file.jpg becomes a file .bmp

I want to be file.jpg.bmp

Please help thanks

  • I guess you can rename the file, appending the `.bmp` at the end, instead of using the `Path.ChangeExtension` API. Look here: https://stackoverflow.com/questions/3218910/rename-a-file-in-c-sharp – Manuel Fabbri Jan 29 '19 at 08:44
  • BMP and JPG are very different formats. Do you *really* want to append `.bmp` to a `.jpg` file and confuse Windows Explorer and any program that tries to read that file as a BMP? – Panagiotis Kanavos Jan 29 '19 at 08:45

1 Answers1

4

Try something like that:

string[] file = Directory.GetFiles(folder_path);
foreach (string myfile in file)
{
      System.IO.File.Move(myfile, myfile + ".bmp");
}