Skip to content

Commit 5501203

Browse files
committed
Abort earlier if target directory does not exists
1 parent 3596572 commit 5501203

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

PatternFileMover/Form1.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ void backgroundWorker1_DoWork(object sender, DoWorkEventArgs eventArgs)
9797
{
9898
if (dataGridView1.Rows[i].Cells[0].Value.ToString().Contains(data.SearchPattern))
9999
{
100+
if (!Directory.Exists(data.TargetDirectory + Path.DirectorySeparatorChar))
101+
{
102+
// the target directory does not existing
103+
// maybe a broken name association or a network drive is not available
104+
// skip this and go on
105+
continue;
106+
}
107+
100108
if (File.Exists(
101109
data.TargetDirectory +
102110
Path.DirectorySeparatorChar +
@@ -113,14 +121,6 @@ void backgroundWorker1_DoWork(object sender, DoWorkEventArgs eventArgs)
113121
);
114122
}
115123

116-
if (!Directory.Exists(data.TargetDirectory + Path.DirectorySeparatorChar))
117-
{
118-
// the target directory does not existing
119-
// maybe a broken name association or a network drive is not available
120-
// skip this and go on
121-
continue;
122-
}
123-
124124
File.Move(
125125
dataGridView1.Rows[i].Cells[0].Value.ToString(),
126126
data.TargetDirectory + Path.DirectorySeparatorChar + Path.GetFileName(dataGridView1.Rows[i].Cells[0].Value.ToString())

0 commit comments

Comments
 (0)