How to rename file in C#

1 Answer

0 votes
using System;
using System.IO;

public class Program
{
    public static void Main(string[] args)
    {
        try {
            if (File.Exists("d:\\data.bin")) {
                File.Move("d:\\data.bin", "d:\\data_new_name.bin");
                Console.WriteLine("rename success");
            }
        }
        catch (IOException iex) {
            Console.WriteLine(iex.Message);
        }
    }
}


/*
run:
 
rename success
 
*/

 



answered Aug 26, 2015 by avibootz
edited Apr 23, 2024 by avibootz

Related questions

1 answer 279 views
279 views asked Aug 22, 2023 by avibootz
1 answer 338 views
1 answer 362 views
362 views asked Jul 12, 2020 by avibootz
1 answer 329 views
329 views asked Mar 10, 2020 by avibootz
1 answer 356 views
1 answer 302 views
302 views asked Jun 9, 2018 by avibootz
1 answer 343 views
343 views asked Aug 26, 2015 by avibootz
...