aps.net C# Renaming an image name

Asked

Viewed 997 times

0

I have an image in a folder and I wanted to change its name only
someone can help me
thank you

example:
original name.jpg

went to:
desired name.jpg

3 answers

3


  • 1

    Remembering that the parameters should be the full path of the files, not just the name.

  • Well noted @jbueno

  • thank you worked very well

  • @Luisoliveira You can mark this answer as correct by marking the just below the arrows to vote...

0

A safe way to do this is to make a copy of your source image, to your target image already with the name you want to use in the source image. For example:

private void copyimage()
    {
        //Caminho padrão para as imagens.(Mude para o diretório aonde suas imagens estão armazenadas).
        string sCaminho = Directory.GetCurrentDirectory() + @"\PastaImagens\";

        //Imagem de origem.
        string sImgOrigem = sCaminho + "NomeImgOrigem.jpg";

        //Imagem com novo nome.
        string sImgDestino = sCaminho + "NomeImgDestino.jpg";

        //Copia a imagem para mesma pasta, porém com o nome diferente.
        File.Copy(sImgOrigem, sImgDestino);

        //Se tudo deu certo, deleta a imagem de origem.
        File.Delete(sImgOrigem);
    }

In case it worked, in the end we delete our source image. This gives a greater security so we do not lose the image for some other problem, especially when we use it in a loop.

-1

insira o código aqui using System.IO;

namespace RenomeandoNomesDasFotos
{
    class Program
    {
        static void Main(string[] args)
        {
            Directory.Move("C:\Imagens\foto.png", "C:\Imagens\fotoRenomeada.png");
        }
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.