Answers for "Backup files"

C#
0

Backup files

using System;
using System.IO;

string sourceDir = @"C:\Users\Jano\Documents\";
string backupDir = @"C:\Users\Jano\Documents\backup\";

string[] textFiles = Directory.GetFiles(sourceDir, "*.txt");

foreach (string textFile in textFiles)
{
    string fileName = textFile.Substring(sourceDir.Length);

    File.Copy(Path.Combine(sourceDir, fileName), 
            Path.Combine(backupDir, fileName), true);
}

Console.WriteLine("Files copied");
Posted by: Guest on October-13-2021

C# Answers by Framework

Browse Popular Code Answers by Language