資源簡(jiǎn)介
C# 動(dòng)態(tài)復(fù)制多個(gè)文件的源碼,高手跳過(guò)
C# 動(dòng)態(tài)復(fù)制多個(gè)文件的源碼,高手跳過(guò)

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
//download?by?http://www.codefans.net
using?System.IO;
namespace?Case09_9
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?button3_Click(object?sender?EventArgs?e)
????????{
????????????if?(textBox2.Text?!=?““)
????????????{
????????????????foreach?(object?o?in?listBox1.SelectedItems)??????//利用foreach循環(huán)把源目錄中選擇的文件復(fù)制到目標(biāo)文件夾中
????????????????{
????????????????????File.Copy(textBox1.Text?+?“\\“?+?o.ToString()?textBox2.Text?+?“\\“?+?o.ToString());
????????????????}
????????????????int?myx?=?listBox1.SelectedItems.Count;???????????????????//復(fù)制文件的個(gè)數(shù)
????????????????string?mystr?=?“已成功復(fù)制“?+?myx.ToString()?+?“個(gè)文件“;
????????????????MessageBox.Show(this?mystr?“信息提示“?MessageBoxButtons.OK?MessageBoxIcon.Information);
????????????}
????????????else
????????????{
????????????????MessageBox.Show(this?“目標(biāo)文件夾不能為空!“?“信息提示“?MessageBoxButtons.OK?MessageBoxIcon.Information);
????????????}
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????folderBrowserDialog1.ShowDialog();???????//瀏覽文件夾對(duì)話框
????????????textBox1.Text?=?folderBrowserDialog1.SelectedPath;????//提取源目錄路徑及名稱(chēng)
????????????if?(textBox1.Text?!=?““)
????????????{
????????????????DirectoryInfo?dir?=?new?DirectoryInfo(textBox1.Text);
????????????????FileInfo[]?f?=?dir.GetFiles();?????????//提取源目錄中所有文件
????????????????for?(int?i?=?0;?i?????????????????{
????????????????????listBox1.Items.Add(f[i]);?????//利用for循環(huán)添加到列表框中
????????????????}
????????????}
????????????else
????????????{
????????????????MessageBox.Show(this?“沒(méi)有選擇源文件夾!“?“信息提示“?MessageBoxButtons.OK?MessageBoxIcon.Information);
????????????}
????????}
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????folderBrowserDialog1.ShowDialog();??????//瀏覽文件夾對(duì)話框
????????????textBox2.Text?=?folderBrowserDialog1.SelectedPath;
????????}
????????private?void?button4_Click(object?sender?EventArgs?e)
????????{
????????????this.Close();
????????????Application.Exit();
????????}
????}
}
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
-----------?---------??----------?-----??----
????????????????48655????????????????????16
評(píng)論
共有 條評(píng)論