搜索到的:
string pLocalFilePath ="";//要復(fù)制的文件路徑
string pSaveFilePath ="";//指定存儲(chǔ)的路徑
if (File.Exists(pLocalFilePath))//必須判斷要復(fù)制的文件是否存在
{
File.Copy(pLocalFilePath, pSaveFilePath, true);//三個(gè)參數(shù)分別是源文件路徑,存儲(chǔ)路徑,若存儲(chǔ)路徑有相同文件是否替換
}
自己應(yīng)用:
多選---->復(fù)制指定文件夾
OpenFileDialog dlg = new OpenFileDialog();
dlg.Multiselect = true;
dlg.DefaultExt = “.dxf”;
dlg.Filter = “(.dxf)|.dxf”;//定義選擇文件的類型
dlg.RestoreDirectory = true;
if (dlg.ShowDialog() == DialogResult.OK)
{
var files = dlg.FileNames;
try
{
foreach (var file in files)
{
string pSaveFilePath = CurDir + file.Substring(file.LastIndexOf("\") + 1);//指定存儲(chǔ)的路徑
if (File.Exists(file))//必須判斷要復(fù)制的文件是否存在
{
File.Copy(file, pSaveFilePath, true);//三個(gè)參數(shù)分別是源文件路徑,存儲(chǔ)路徑,若存儲(chǔ)路徑有相同文件是否替換
}
}
}
catch (IOException ioex)
{
Console.WriteLine(ioex.Message);
}
}文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-420614.html
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-420614.html
到了這里,關(guān)于C#選定文件復(fù)制到指定文件夾的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!