Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

โปรแกรม C# เปลี่ยนชื่อไฟล์

ใช้เมธอด Move เพื่อเปลี่ยนชื่อไฟล์

สมมติว่าชื่อไฟล์คือ:

D:\tom.txt

ตอนนี้ เพื่ออัปเดตเป็นดังต่อไปนี้ ให้ใช้เมธอด Move():

D:\tim.txt

มาดูโค้ดทั้งหมดกัน

ตัวอย่าง

using System;
using System.IO;

public class Demo
{
    public static void Main()
    {
        File.Move(@"D:\tom.txt", @"D:\tim.txt");
        Console.WriteLine("File moved successfully!");
    }
}