static readonly private string path = AppDomain.CurrentDomain.BaseDirectory;
string file_name = "文件名.文件类型";
string s_path = path + file_name;
string d_path = folderBrowserDialog1.SelectedPath + "//" + file_name;
if (File.Exists(s_path))
{
File.Copy(s_path, d_path, true);
if (File.Exists(d_path))
lb_error_info.Text = "复制文件" + file_name + "至" + folderBrowserDialog1.SelectedPath + "成功!/n";
}
else
{
lb_error_info.Text = "源文件不存在!";
return;
}
当然,WindowsForm里有FolderBrowserDialog和Label控件,分别名为folderBrowserDialog1和lb_error_info
//拷贝bin/Debug下文件到目标文件夹
string source_path_Permanence = path + "Permanence//";
string dest_path_Permanence = folderBrowserDialog1.SelectedPath + "//Permanence//";
CopyFolder(source_path_Permanence, dest_path_Permanence);
private void CopyFolder(string source_path, string dest_path)
{
//检查文件夹
if (!Directory.Exists(dest_path))
Directory.CreateDirectory(dest_path);
//子文件夹
foreach (string sub_path in Directory.GetDirectories(source_path))
CopyFolder(sub_path + "//", dest_path + Path.GetFileName(sub_path) + "//");
//文件
foreach (string file in Directory.GetFiles(source_path))
File.Copy(file, dest_path + Path.GetFileName(file), true);
}