上面是我创建的Winform窗体,拉控件就这样,groupbox显示文件的相关信息
代码如下:
//实例化文件对话框的类对象
OpenFileDialog ofg = new OpenFileDialog();
//存放源文件路径,一个存放目的文件路径
string filepath;
string filepath1;
//获取文件对象
FileInfo file = null;
private void button1_Click(object sender, EventArgs e)
{
//调用对象的函数
if (ofg.ShowDialog() == DialogResult.OK) {
//获取文件的路径
filepath = ofg.FileName;
this.txb_Path1.Text = filepath;
//创建文件对象
file = new FileInfo(filepath);
//获取文件名
this.txtFileName.Text = file.Name;
//获取文件完整路径
this.txtFilePathAll.Text = file.FullName;
//获取文件所在的根目录
this.txtFileRoot.Text = file.DirectoryName;
this.txtCreatetime.Text = file.CreationTime.ToString();
this.txtVisttime.Text = file.LastAccessTime.ToString();
this.txtUpdatetime.Text = file.LastWriteTime.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
//获取文件目录
FolderBrowserDialog fog = new FolderBrowserDialog();
if (fog.ShowDialog() == DialogResult.OK)
{
//获取存放目录(文件夹)
filepath1 = fog.SelectedPath;
this.txb_Path2.Text = filepath1;
}
}
private void button3_Click(object sender, EventArgs e)
{
filepath1 = [email protected]"\" + file.Name;
File.Copy(filepath,filepath1);
MessageBox.Show("复制成功!");
}
运行效果如下: