private
void
btnSave_Click(
object
sender, EventArgs e)
{
#region 静态复制文件(写死)
string
desPath =
@"c:\1\1.chm"
;
if
(File.Exists(desPath))
{
if
(MessageBox.Show((
"文件已存在,是否覆盖"
),
"询问"
, MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.Yes)
{
File.Copy(
@"c:\ls\w3.chm"
, desPath,
true
);
MessageBox.Show(
"覆盖成功"
);
}
}
else
{
File.Copy(
@"c:\ls\w3.chm"
, desPath,
true
);
MessageBox.Show(
"复制成功"
);
}
openFileDialog1.InitialDirectory=(
@"c:\1"
);
openFileDialog1.Filter =
"可执行程序|*.exe|TXT文本|*.txt|图片文件|*.jpg|所有文件|*.*"
;
if
(openFileDialog1.ShowDialog() == DialogResult.OK)
{
if
(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
File.Copy(openFileDialog1.FileName, saveFileDialog1.FileName,
true
);
MessageBox.Show(
"保存完成"
);
}
}
#endregion
}
#region 动态
private
void
btnCopyContents_Click(
object
sender, EventArgs e)
{
string
oldDir, newDir;
FolderBrowserDialog sourceFolder =
new
FolderBrowserDialog();
sourceFolder.Description =
"请选择要复制的文件夹"
;
if
(sourceFolder.ShowDialog()==DialogResult.OK)
{
oldDir = sourceFolder.SelectedPath;
sourceFolder.Description =
"请选择要复制到的文件夹"
;
if
(sourceFolder.ShowDialog()== DialogResult.OK)
{
newDir = sourceFolder.SelectedPath;
string
[] files = Directory.GetFiles(oldDir);
foreach
(
string
filepath
in
files)
{
string
nFileName ;
nFileName = filepath.Substring(filepath.LastIndexOf(
"\\"
) + 1);
File.Copy(filepath, newDir +
"\\"
+ nFileName,
true
);
}
}
}
}
#endregion