-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDataCopy.cs
More file actions
69 lines (63 loc) · 2.29 KB
/
DataCopy.cs
File metadata and controls
69 lines (63 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BackUpDesktop
{
internal class DataCopy
{
public static Task FFCopy(string[] folders)
{
string folderName = "";
string targetPath = Program.BackUpPath;
string[] desktop;
string[] files;
long TotalSize = 0;
foreach (string s in folders)
{
TotalSize += Info.DirSize(new DirectoryInfo(s));
}
Console.WriteLine($"\nTotal Backup Size: {Info.SizeSuffix(TotalSize)}\nPress any key to continue");
Console.ReadLine();
foreach (string s in folders)
{
desktop = Directory.GetDirectories(s);
files = Directory.GetFiles(s, "*.*", SearchOption.TopDirectoryOnly);
Console.WriteLine($"Path: {s} Folders: {desktop.Count()} Files: {files.Count()} size {Info.SizeSuffix(Info.DirSize(new DirectoryInfo(s)))}");
folderName = new FileInfo(s).Name;
string EndPath = Path.Combine(targetPath, folderName);
Directory.CreateDirectory(EndPath);
CopyFolder(s, EndPath);
}
return Task.CompletedTask;
}
static public void CopyFolder(string sourceFolder, string destFolder)
{
if (!Directory.Exists(destFolder))
Directory.CreateDirectory(destFolder);
try
{
string[] files = Directory.GetFiles(sourceFolder);
foreach (string file in files)
{
string name = Path.GetFileName(file);
string dest = Path.Combine(destFolder, name);
File.Copy(file, dest);
}
}catch { };
try
{
string[] folders = Directory.GetDirectories(sourceFolder);
foreach (string folder in folders)
{
string name = Path.GetFileName(folder);
string dest = Path.Combine(destFolder, name);
CopyFolder(folder, dest);
}
}
catch { }
}
}
}