-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Copy several files to destination directory (optionally) #34
Open
MoxieWhimsy
wants to merge
5
commits into
UniToolsTeam:master
Choose a base branch
from
MoxieWhimsy:feature/copy-files-to-directory
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
855e115
Feat: Copy several files to destination directory (optionally)
MoxieWhimsy 53a42bc
Merge branch 'UniToolsTeam:master' into feature/copy-files-to-directory
MoxieWhimsy 9a6f023
Revert "Feat: Copy several files to destination directory (optionally)"
MoxieWhimsy f4b7e9d
Feat: Copy multiple files to destination directory
MoxieWhimsy e39ef60
Added source directory property
MoxieWhimsy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check is the m_sourceDirectory path is a directory path. If not - throw an exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I will make sure
m_destinationDirectory
is a directory path.