Change File Extension Using C#

后端 未结 5 1474
北荒
北荒 2020-11-29 06:34

I have many file types: pdf, tiff, jpeg, bmp. etc. My question is how can I change file extension? I tried this:

my file= c:/my documents/my images/cars/a.jp         


        
5条回答
  •  猫巷女王i
    2020-11-29 06:39

    There is: Path.ChangeExtension method. E.g.:

    var result = Path.ChangeExtension(myffile, ".jpg");
    

    In the case if you also want to physically change the extension, you could use File.Move method:

    File.Move(myffile, Path.ChangeExtension(myffile, ".jpg"));
    

提交回复
热议问题