Skip to content

Commit 9a3de5e

Browse files
committed
Prevent exception while copying a file if target exists
1 parent c856e31 commit 9a3de5e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

PatternFileMover/Action/Copy.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ internal class Copy : AbstractAction
77
{
88
public bool DoCopy()
99
{
10-
File.Copy(
11-
this.GetSourcePath(),
12-
this.GetTargetPath() +
13-
Path.DirectorySeparatorChar +
14-
Path.GetFileName(this.GetCurrent().Cells[0].Value.ToString()
15-
)
16-
);
10+
try
11+
{
12+
File.Copy(
13+
this.GetSourcePath(),
14+
this.GetTargetPath() +
15+
Path.DirectorySeparatorChar +
16+
Path.GetFileName(this.GetCurrent().Cells[0].Value.ToString()
17+
)
18+
);
19+
}
20+
catch (IOException)
21+
{
22+
return false;
23+
}
1724

1825
return true;
1926
}

0 commit comments

Comments
 (0)