Advertisement
andruhovski

CopyFile Demo

Sep 10th, 2018
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8.  
  9. namespace Demo20180906
  10. {
  11.     class Program
  12.     {
  13.         [STAThread]
  14.         static void Main(string[] args)
  15.         {
  16.            //Дано деяку папку A. Скопіювати усі файли розміром 100 байт і більше в папку B.
  17.             var folderA = @"D:\ABC";
  18.             var folderB = @"D:\ABC_New";
  19.             var di = new DirectoryInfo(folderA);
  20.             var files = di.GetFiles();
  21.             if (!Directory.Exists(folderB))
  22.                 Directory.CreateDirectory(folderB);
  23.             foreach (var file in files)
  24.             {
  25.                 Console.WriteLine("{0} - {1}", file.Name, file.Length);
  26.                 if (file.Length>=100)
  27.                 {
  28.                     try
  29.                     {
  30.                         file.CopyTo(Path.Combine(folderB, file.Name));
  31.                     }
  32.                     catch (IOException ex)
  33.                     {
  34.                         Console.WriteLine("Error: {0} with {1}",ex.Message, file.Name);
  35.                     }
  36.                 }  
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement