소스 검색

Don't throw error when 'Force' switch is specified

This fixes error when 'Move-Item2 -Force' would not overwrite existing files
tags/4.2.4
Kris Borowinski 6 년 전
committed by GitHub
부모
커밋
d5f552df8c
1개의 변경된 파일3개의 추가작업 그리고 3개의 파일을 삭제
  1. +3
    -3
      NTFSSecurity/ItemCmdlets/MoveItem2.cs

+ 3
- 3
NTFSSecurity/ItemCmdlets/MoveItem2.cs 파일 보기

@@ -85,7 +85,7 @@ namespace NTFSSecurity
actualDestination = destination;
}

if (File.Exists(actualDestination))
if (!force & File.Exists(actualDestination))
{
WriteError(new ErrorRecord(new AlreadyExistsException(), "DestinationFileAlreadyExists", ErrorCategory.ResourceExists, actualDestination));
return;
@@ -97,7 +97,7 @@ namespace NTFSSecurity
{
if (ShouldProcess(resolvedPath, "Move File"))
{
((FileInfo)item).MoveTo(actualDestination, MoveOptions.CopyAllowed, PathFormat.RelativePath);
((FileInfo)item).MoveTo(actualDestination, force ? MoveOptions.ReplaceExisting : MoveOptions.CopyAllowed, PathFormat.RelativePath);
WriteVerbose(string.Format("File '{0}' moved to '{0}'", resolvedPath, destination));
}
}
@@ -105,7 +105,7 @@ namespace NTFSSecurity
{
if (ShouldProcess(resolvedPath, "Move Directory"))
{
((DirectoryInfo)item).MoveTo(actualDestination, MoveOptions.CopyAllowed, PathFormat.RelativePath);
((DirectoryInfo)item).MoveTo(actualDestination, force ? MoveOptions.ReplaceExisting : MoveOptions.CopyAllowed, PathFormat.RelativePath);
WriteVerbose(string.Format("Directory '{0}' moved to '{0}'", resolvedPath, destination));
}
}


불러오는 중...
취소
저장