发布时间:2019-09-20 07:29:22编辑:auto阅读(1728)
using System;
using System.IO;
class Test
{
public static void Main()
{
string fileName = "C:\\autoexec.bat";
FileInfo fileInfo = new FileInfo(fileName);
if (!fileInfo.Exists)
{
return;
}
Console.WriteLine("{0} has a directoryName of {1}",fileName,fileInfo.DirectoryName);
/* 下面是代码的处理结果,
* 实际的结果因机器不同:
*
* C:\autoexec.bat has a directoryName of C:\
*/
}
} |
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace FileOptionApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 复制文本文件
/// </summary>
private void button1_Click(object sender, EventArgs e)
{
string somefile = @"C:\Documents and Settings\Administrator\My Documents\SQL Server2000安装故障.txt";
string target = @"c:\2.txt";
if (!File.Exists(somefile))
{
MessageBox.Show("文件不存在!");
}
else
{
if (File.Exists(target))
{
File.Delete(target);
}
File.Copy(somefile, target);
MessageBox.Show("文件复制成功!");
}
}
/// <summary>
/// 创建文本文件
/// </summary>
private void button2_Click(object sender, EventArgs e)
{
string target = @"c:\2.txt";
if (File.Exists(target))
{
File.Delete(target);
}
File.CreateText(target);
}
/// <summary>
/// 删除文本文件
/// </summary>
private void button3_Click(object sender, EventArgs e)
{
string target = @"c:\2.txt";
if (File.Exists(target))
{
File.Delete(target);
MessageBox.Show("文件删除成功!");
}
}
}
} |
private void button1_Click(object sender, EventArgs e)
{
string path = @"C:\WINDOWS\IE4 Error Log.txt";
string target = @"c:\1.txt";
FileInfo myfile = new FileInfo(path);
if (!myfile.Exists)
{
MessageBox.Show("对不起,未发现路径文件!");
}
else
{
myfile.CopyTo(target);
MessageBox.Show("复制成功!");
}
} |
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace FileOptionApplication
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
/// <summary>
/// 获取文件信息单击事件
/// </summary>
private void button1_Click(object sender, EventArgs e)
{
string somefile = @"C:\Documents and Settings\Administrator\My Documents\SQL Server2000安装故障.txt";
FileInfo myfile = new FileInfo(somefile);
if (myfile.Exists)
{
MessageBox.Show("文件已经存在");
label1.Text = "文件创建时间:" + myfile.CreationTime.ToString();
label2.Text = "文件夹:" + myfile.Directory.ToString();
label3.Text = "文件夹名称:" + myfile.DirectoryName.ToString() + ",文件扩展名:" + myfile.Extension.ToString();
}
else
{
MessageBox.Show("文件并不存在");
}
}
}
} |
上一篇: Python读写CSV文件
下一篇: Python学习笔记整理(二)pytho
47839
46384
37276
34727
29311
25969
24904
19946
19540
18019
5788°
6410°
5925°
5959°
7062°
5908°
5941°
6435°
6403°
7774°