-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
54 lines (50 loc) · 1.49 KB
/
Copy pathForm1.cs
File metadata and controls
54 lines (50 loc) · 1.49 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
using Newtonsoft.Json;
namespace Flyff_File_Mover
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class FilePath
{
public string source { get; set; }
public string destination { get; set; }
}
public class FilePathConfig
{
public List<FilePath> files { get; set; }
}
private void button1_Click(object sender, EventArgs e)
{
try
{
var config = LoadFilePaths("path.json");
foreach (var file in config.files)
{
CopyFile(file.source, file.destination);
}
toolStripStatusLabel1.Text = "Status: Done.";
}
catch (Exception ex)
{
toolStripStatusLabel1.Text = $"Status: {ex.Message}";
}
}
private FilePathConfig LoadFilePaths(string path)
{
var json = File.ReadAllText(path);
return JsonConvert.DeserializeObject<FilePathConfig>(json);
}
private void CopyFile(string source, string destination)
{
string destinationDirectory = Path.GetDirectoryName(destination);
if (!Directory.Exists(destinationDirectory))
{
Directory.CreateDirectory(destinationDirectory);
}
File.Copy(source, destination, true);
}
}
}