C# File Move

Description

File Move Moves a specified file to a new location, providing the option to specify a new file name.

Syntax

File.Move has the following syntax.


public static void Move(
  string sourceFileName,
  string destFileName
)

Parameters

File.Move has the following parameters.

  • sourceFileName - The name of the file to move.
  • destFileName - The new path for the file.

Returns

File.Move method returns

Example

The following example moves a file.


//  ww  w. j a  v  a  2  s .  c om
using System;
using System.IO;

class Test 
{
    public static void Main() 
    {
        string path = @"c:\temp\MyTest.txt";
        string path2 = @"c:\temp2\MyTest.txt";
        File.Move(path, path2);
    }
}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter