Quantcast
Channel: Welcome To TechBrothersIT
Viewing all articles
Browse latest Browse all 1949

C# - How to Move files from a folder to Another Folder in C Sharp

$
0
0

Scenario: Download Script

You are working as C# developer, you need to create a program that should move the files from source folder to destination folder. 

Below code can be used to move all the files from a folder to another folder.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace TechBrothersIT.com_CSharp_Tutorial
{
class Program
{
static void Main(string[] args)
{
//Provider Source Folder Path
string SourceFolder = @"C:\Source\";
//Provide Destination Folder path
string DestinationFolder = @"C:\Destination\";

var files = new DirectoryInfo(SourceFolder).GetFiles("*.*");

//Loop throught files and Move to destination folder
foreach (FileInfo filein files)
{

file.MoveTo(DestinationFolder+file.Name);

}

}
}
}

Viewing all articles
Browse latest Browse all 1949

Trending Articles