-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCopyFilesToDirectory.cs
More file actions
46 lines (41 loc) · 1.74 KB
/
Copy pathCopyFilesToDirectory.cs
File metadata and controls
46 lines (41 loc) · 1.74 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
using System.IO;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
namespace UniTools.Build
{
[CreateAssetMenu(
fileName = nameof(CopyFilesToDirectory),
menuName = MenuPaths.IO + nameof(CopyFilesToDirectory)
)]
public sealed class CopyFilesToDirectory : BuildStep
{
[SerializeField] private PathProperty m_sourceDirectory = default;
[SerializeField] private PathProperty[] m_sourceFiles = default;
[SerializeField] private PathProperty m_destinationDirectory = default;
public override async Task Execute()
{
var sourceFolder = m_sourceDirectory.ToString();
var hasNoSourceFolder = string.IsNullOrEmpty(sourceFolder);
var destinationFolder = m_destinationDirectory.ToString();
if (!hasNoSourceFolder && !Directory.Exists(sourceFolder))
{
throw new DirectoryNotFoundException($"Source folder: {sourceFolder} does not exist!");
}
if (!Directory.Exists(destinationFolder))
{
throw new DirectoryNotFoundException($"Destination folder {destinationFolder} does not exist!");
}
foreach (var sourceFile in m_sourceFiles)
{
var filePath = sourceFile.ToString();
var fileName = Path.GetFileName(filePath);
var source = hasNoSourceFolder ? filePath : Path.Combine(sourceFolder, filePath);
var destination = Path.Combine(destinationFolder, fileName);
FileUtil.DeleteFileOrDirectory(destination);
FileUtil.CopyFileOrDirectory(source, destination);
}
await Task.CompletedTask;
}
}
}