private MoveTo ( String destFileName ) : void | ||
destFileName | String | |
return | void |
using System.IO; // Create a FileInfo object FileInfo fileInfo = new FileInfo("C:\old\file.txt"); // Move the file to a new location fileInfo.MoveTo("C:\new\file.txt");
using System.IO; // Create a FileInfo object FileInfo fileInfo = new FileInfo("C:\old\file.txt"); // Rename the file and move it to a new location fileInfo.MoveTo("C:\new\newfile.txt");This example creates a FileInfo object that represents a file located at "C:\old\file.txt". Then it renames the file to "newfile.txt" and moves it to a new location at "C:\new\". The MoveTo method is part of the System.IO namespace in C#.