Winform---文件夹操作
一、文件夹的操作
private void button1_Click(object sender, EventArgs e)
{
//文件夹操作
////新建文件夹
//Directory.CreateDirectory(@"F:\zhoubinn");
//DirectoryInfo dir = new DirectoryInfo(@"F:\zhoubin1");
//dir.Create();
}
private void button2_Click(object sender, EventArgs e)
{//删除文件夹
//Directory.Delete(@"F:\zhoubinn");
//DirectoryInfo aa = new DirectoryInfo(@"F:\zhoubin1");
//aa.Create();
}
private void button4_Click(object sender, EventArgs e)
{// 判断文件夹是否存在
//bool bo = Directory.Exists(@"F:\zhoubinn");
//if (bo == true)
//{
// MessageBox.Show("文件夹存在");
//}
//else
//{
// MessageBox.Show("文件不不存在");
//}
}
private void button3_Click(object sender, EventArgs e)
{ // 获取某个文件夹内子文件名
//string[] aa = Directory.GetFiles(@"F:\zhoubin");
////listBox1.Items.Clear();
//foreach (string a in aa)
//{///显示在listbox里面
// listBox1.Items.Add(a);
//}
//DirectoryInfo name = new DirectoryInfo(@"F:\zhoubin");
//FileInfo[] af = name.GetFiles();
//// listBox1.Items.Clear();
//foreach (FileInfo a in af)
//{
// listBox1.Items.Add(a.FullName);
//}
}
private void button5_Click(object sender, EventArgs e)
{ // 获取某个文件中子文件中的名字
//string[] name = Directory.GetDirectories(@"F:\zhoubin");
//listBox1.Items.Clear();
//foreach (string a in name)
//{
// listBox1.Items.Add(a);
//}
//DirectoryInfo ac = new DirectoryInfo(@"F:zhoubin");
//DirectoryInfo[] s = ac.GetDirectories();
//foreach (DirectoryInfo a in s)
//{
// listBox1.Items.Add(a);
//}
}
private void button8_Click(object sender, EventArgs e)
{
//获取文件夹的创建时间,最后一次的访问时间 最后一次写入时间
//string r = @"F:\zhoubin";
//DateTime createtime = Directory.GetCreationTime(r);
//DateTime fangwen = Directory.GetLastAccessTime(r);
//DateTime xieru = Directory.GetLastWriteTime(r);
//listBox1.Items.Add(createtime);
//listBox1.Items.Add(fangwen);
//listBox1.Items.Add(xieru);
DirectoryInfo afg = new DirectoryInfo(@"F:\zhoubin1");
DateTime a = afg.CreationTime;
DateTime b = afg.LastAccessTime;
DateTime c = afg.LastWriteTime;
listBox1.Items.Add(afg.LastWriteTime);
listBox1.Items.Add(b);
listBox1.Items.Add(c);
}
private void button9_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
}
private void button6_Click(object sender, EventArgs e)
{
string path = @"F:\zhoubin1";
Directory.SetLastWriteTime(path,new DateTime(2030,3,4));
Directory.SetLastAccessTime(path,new DateTime(2040,5,6));
Directory.SetCreationTime(path,new DateTime(1984,4,5));
}
private void button7_Click(object sender, EventArgs e)
{
string a = @"F:\zhoubin\123";
string b = @"F:\zhoubin1\";
Directory.Move(a,b);
}
}
二、 读写文件的操作
private void button1_Click(object sender, EventArgs e)
{
// 读取文件内容
String path = @"F:\wenjianduqu\读取2.doc";
//实例化流文件
FileStream stream = new FileStream(path, FileMode.Open);
//将文件转换为二进制字符;
byte[] nr = new byte[stream.Length];
//stream.Write();
//读取流文件
stream.Read(nr, 0, nr.Length);
//关闭流文件
stream.Close();
//将读取的流文件从二进制转化为字符串
// String s = System.Text.Encoding.Default.GetString(nr);
string s = System.Text.Encoding.UTF32.GetString(nr);
textBox1.Text = s;
}
private void button2_Click(object sender, EventArgs e)
{
// 读取文件内内容方法二
string path = @"F:\duquwenjian\读取2.txt";
FileStream stream = new FileStream(path, FileMode.Open);
StreamReader reader = new StreamReader(stream, Encoding.Default);
string ss = reader.ReadToEnd();
reader.Close();
stream.Close();
textBox1.Text = ss;
}
private void button3_Click(object sender, EventArgs e)
{
//读取文件内容方法三
string path = @"D:\duqu.txt";
StreamReader reader = new StreamReader(path, Encoding.Default);
string a = reader.ReadToEnd();
textBox1.Text = a;
}
private void button4_Click(object sender, EventArgs e)
{
//读取文件内容方法4
DialogResult dia = open.ShowDialog();
if (dia == System.Windows.Forms.DialogResult.OK)
{
StreamReader reader = new StreamReader(open.FileName, Encoding.Default);
string ssse = reader.ReadToEnd();
reader.Close();
textBox1.Text = ssse;
}
}
private void button5_Click(object sender, EventArgs e)
{
// 写入文件内容
string path = @"F:\wenjianduqu\abc.txt";
StreamWriter writ = new StreamWriter(path, false, Encoding.Default);
//fause 将源文件全部替换;ture 在源文件的基础上追加
writ.WriteLine(textBox1.Text);
writ.Close();
}
private void button6_Click(object sender, EventArgs e)
{
//写入内容2
DialogResult dia = save.ShowDialog();
if (dia == System.Windows.Forms.DialogResult.OK)
{
StreamWriter writ = new StreamWriter(save.FileName, true, Encoding.Default);
writ.WriteLine(textBox1.Text);
writ.Close();
}
}
private void button7_Click(object sender, EventArgs e)
{
//写入内容3
DialogResult dia = save.ShowDialog();
if (dia == System.Windows.Forms.DialogResult.OK)
{
FileStream stream = new FileStream(save.FileName, FileMode.OpenOrCreate);
StreamWriter weri = new StreamWriter(stream);
weri.WriteLine(textBox1.Text);
stream.Close();
weri.Close();
}
}
private void button8_Click(object sender, EventArgs e)
{
//写入文件方法4
if (save.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
byte[] nr = System.Text.Encoding.Default.GetBytes(textBox1.Text);
FileStream strea = new FileStream(save.FileName, FileMode.OpenOrCreate);
strea.Write(nr, 0, nr.Length);
strea.Close();
}
}
Winform---文件夹操作的更多相关文章
- 文件及文件夹操作- File类、Directory 类、FileInfo 类、DirectoryInfo 类
文件及文件夹操作: C/S:WinForm可以操作客户端文件 Client ServerB/S:Brower Server 命名空间:using system .IO; 1. File类: 创建:Fi ...
- [No000083]文件与文件夹操作
#region Folder option 文件夹操作 /// <summary> /// 指定目录是否存在 /// </summary> /// <param name ...
- PHP 文件夹操作「复制、删除、查看大小」递归实现
PHP虽然提供了 filesize.copy.unlink 等文件操作的函数,但是没有提供 dirsize.copydir.rmdirs 等文件夹操作的函数(rmdir也只能删除空目录).所以只能手动 ...
- .Net文件*夹*操作
一.文件夹操作 Directory类,DirectoryInfo类.使用using System.IO命名空间 (一)创建文件夹 方法一: private string path = @"F ...
- iOS开发——Swift篇&文件,文件夹操作
文件,文件夹操作 ios开发经常会遇到读文件,写文件等,对文件和文件夹的操作,这时就可以使用NSFileManager,NSFileHandle等类来实现. 下面总结了各种常用的操作: 1,遍 ...
- Python的文件与文件夹操作
Python的文件与文件夹操作 Python OS模块 1.重命名:os.rename(old, new) 2.删除:os.remove(file) 3.列出目录下的文件 :os.listdir(pa ...
- linux —— 学习笔记(文件、文件夹操作)
目录:1.常用的文件文件夹操作 2.文件属性的设置 1.常用的文件文件夹操作 mkdir 创建文件夹 -p 如果指定 a/b/c 时 a .b 不存在,一起创建出来 cp 复制文件或文件 ...
- (WinForm)文件夹状态监控,最小化到托盘,开机自启动
原文 (WinForm)文件夹状态监控,最小化到托盘,开机自启动 . 文件夾監控(監測文件夾中的文件動態): //MSDN上的例子 public class Watcher { public stat ...
- c# 封装的文件夹操作类之复制文件夹
c# 封装的文件夹操作类之复制文件夹 一.复制文件夹原理: 1.递归遍历文件夹 2.复制文件 二.FolderHelper.cs /// <summary> /// 文件夹操作类 /// ...
- Python_文件与文件夹操作
''' os模块除了提供使用操作系统功能和访问文件系统的简便方法之外,还提供了大量文件与文件夹操作的方法. os.path模块提供了大量用于路径判断.切分.连接以及文件夹遍历的方法. shutil模块 ...
随机推荐
- Hadoop伪分布配置与基于Eclipse开发环境搭建
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- 使用jquery获取父元素或父节点的方法
今天面试题问到了,没答上,jq要继续学习啊 jquery获取父元素方法比较多,比如parent(),parents(),closest()这些都能帮你实现查找父元素或节点,下面我们来一一讲解: 先举个 ...
- radvd.conf RADVD配置文件内容部分解析
interface eth0{ AdvSendAdvert on; #启用路由器公告(RA)功能 MinRtrAdvInterval ; #每隔30-100秒间隔发送公告消息 MaxRtrAdvInt ...
- Java带包编译运行
package cn.togeek.job; public class Test { public static void main(String[] args) throws Exception { ...
- C#中Thread类中Join方法的理解(转载)
指在一线程里面调用另一线程join方法时,表示将本线程阻塞直至另一线程终止时再执行 比如 using System; namespace TestThreadJoin { class Pro ...
- 车牌识别--S5PV210測试
cortex-A8(S5PV210) Linux-3.9.7 arm-linux-gcc 4.5.1(FriendlyARM) 根文件系统:NFS 软浮点执行结果: [liujia@210]#./so ...
- AnimImageView
https://github.com/eltld/AnimImageView
- pushState onpopstate
转载自:http://www.cnblogs.com/gaoxue/p/3885796.html 参考MDN: https://developer.mozilla.org/zh-CN/docs/DOM ...
- 【JavaScript】apply和call的区别在哪?
我在一开始看到javascript的函数apply和call时,非常的模糊,看也看不懂,最近在网上看到一些文章对apply方法和call的一些示例,总算是看的有点眉目了,在这里我做如下笔记,希望和大家 ...
- Oracle—用户管理的完全恢复(四)
在用户管理的备份(三)中,最后打开数据库时,用了alter database open resetlogs;的命令,这里为什么用resetlogs命令? 一.resetlogs的作用 1.将当前的日志 ...