Implemented file copying

This commit is contained in:
Daniel Brunner
2017-07-09 15:33:27 +02:00
parent 22d55ebbd4
commit 8f8982bbe6
2 changed files with 60 additions and 3 deletions

View File

@@ -47,7 +47,7 @@
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(629, 61);
this.panel1.Size = new System.Drawing.Size(846, 61);
this.panel1.TabIndex = 0;
//
// button2
@@ -84,7 +84,7 @@
this.objectListView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.objectListView1.Location = new System.Drawing.Point(0, 61);
this.objectListView1.Name = "objectListView1";
this.objectListView1.Size = new System.Drawing.Size(629, 773);
this.objectListView1.Size = new System.Drawing.Size(846, 773);
this.objectListView1.TabIndex = 1;
this.objectListView1.UseCompatibleStateImageBehavior = false;
this.objectListView1.UseOverlays = false;
@@ -116,7 +116,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(629, 834);
this.ClientSize = new System.Drawing.Size(846, 834);
this.Controls.Add(this.objectListView1);
this.Controls.Add(this.panel1);
this.Name = "MainForm";

View File

@@ -114,7 +114,64 @@ namespace MusicOrganizer
private void button2_Click(object sender, EventArgs e)
{
string targetFolder;
using (var dialog = new FolderBrowserDialog())
{
var result = dialog.ShowDialog();
if (result != DialogResult.OK)
return;
if (string.IsNullOrWhiteSpace(dialog.SelectedPath))
return;
targetFolder = dialog.SelectedPath;
}
foreach(var item in items)
{
var bpmPath = Path.Combine(targetFolder, item.bpm);
again0:
if(!Directory.Exists(bpmPath))
try
{
Directory.CreateDirectory(bpmPath);
}
catch(Exception ex)
{
var result = MessageBox.Show(string.Format("Error occured when creating bpm folder for file\n\n{0}\n\n{1}", item.filename, ex.Message), "Error occured", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
switch (result)
{
case DialogResult.Abort: return;
case DialogResult.Retry: goto again0;
case DialogResult.Ignore: continue;
default: throw new Exception("Unknown option clicked.");
}
}
var target = Path.Combine(bpmPath, Path.GetFileName(item.filename));
again1:
try
{
File.Copy(item.filename, target);
}
catch(Exception ex)
{
var result = MessageBox.Show(string.Format("Error occured when copying file\n\n{0}\n\nto bpmfolder\n\n{1}\n\n{2}", item.filename, target, ex.Message), "Error occured", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
switch (result)
{
case DialogResult.Abort: return;
case DialogResult.Retry: goto again1;
case DialogResult.Ignore: continue;
default: throw new Exception("Unknown option clicked.");
}
}
}
}
}
}