C# 將文件夾中文件復制到另一個文件夾
//新建一個文件夾
var imgPath = Directory.GetCurrentDirectory() + "\\DevicePic1";
if (!Directory.Exists(imgPath))
{
Directory.CreateDirectory(imgPath);
}
var a = picpath;//需要進行復制的圖片的路徑
var b= a.Substring(a.LastIndexOf('.'));//截取后綴名
var newname = imgPath + "\\rename" + b;//目標文件夾中文件的名稱,即將復制后對文件進行重命名
var nf = Path.Combine(newname);//將新的文件名稱路徑字符串結合成路徑。
File.Copy(a,nf);//進行文件復制,第一個參數是需要復制的文件路徑,第二個參數是目標文件夾中文件路徑
pictureBox2.Image=Image.FromFile(nf);
復制代碼
(編輯:雷林鵬 來源:網絡)