一、文件夹的操作
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---文件夹操作的更多相关文章

  1. 文件及文件夹操作- File类、Directory 类、FileInfo 类、DirectoryInfo 类

    文件及文件夹操作: C/S:WinForm可以操作客户端文件 Client ServerB/S:Brower Server 命名空间:using system .IO; 1. File类: 创建:Fi ...

  2. [No000083]文件与文件夹操作

    #region Folder option 文件夹操作 /// <summary> /// 指定目录是否存在 /// </summary> /// <param name ...

  3. PHP 文件夹操作「复制、删除、查看大小」递归实现

    PHP虽然提供了 filesize.copy.unlink 等文件操作的函数,但是没有提供 dirsize.copydir.rmdirs 等文件夹操作的函数(rmdir也只能删除空目录).所以只能手动 ...

  4. .Net文件*夹*操作

    一.文件夹操作 Directory类,DirectoryInfo类.使用using System.IO命名空间 (一)创建文件夹 方法一: private string path = @"F ...

  5. iOS开发——Swift篇&文件,文件夹操作

    文件,文件夹操作   ios开发经常会遇到读文件,写文件等,对文件和文件夹的操作,这时就可以使用NSFileManager,NSFileHandle等类来实现. 下面总结了各种常用的操作:   1,遍 ...

  6. Python的文件与文件夹操作

    Python的文件与文件夹操作 Python OS模块 1.重命名:os.rename(old, new) 2.删除:os.remove(file) 3.列出目录下的文件 :os.listdir(pa ...

  7. linux —— 学习笔记(文件、文件夹操作)

    目录:1.常用的文件文件夹操作 2.文件属性的设置 1.常用的文件文件夹操作 mkdir  创建文件夹 -p 如果指定 a/b/c 时 a .b 不存在,一起创建出来 cp       复制文件或文件 ...

  8. (WinForm)文件夹状态监控,最小化到托盘,开机自启动

    原文 (WinForm)文件夹状态监控,最小化到托盘,开机自启动 . 文件夾監控(監測文件夾中的文件動態): //MSDN上的例子 public class Watcher { public stat ...

  9. c# 封装的文件夹操作类之复制文件夹

    c#  封装的文件夹操作类之复制文件夹 一.复制文件夹原理: 1.递归遍历文件夹 2.复制文件 二.FolderHelper.cs /// <summary> /// 文件夹操作类 /// ...

  10. Python_文件与文件夹操作

    ''' os模块除了提供使用操作系统功能和访问文件系统的简便方法之外,还提供了大量文件与文件夹操作的方法. os.path模块提供了大量用于路径判断.切分.连接以及文件夹遍历的方法. shutil模块 ...

随机推荐

  1. Castle学习笔记----初探IOC容器

    通常IOC实现的步骤为-->建立容器-->加入组件-->获取组件-->使用组件. 1.建立容器 建立容器也就是IWindsorContainer.接着我门要向容器中注册服务,并 ...

  2. 关于TabControl的Trigger【项目】

    我有一个TabControl <TabControl x:Name="ToolSystemSection" Grid.Row="4" ContentTem ...

  3. 本地存储(cookie&sessionStorage&localStorage)

    好文章,最全面.就查它吧:https://segmentfault.com/a/1190000004556040 1.DOM存储:https://developer.mozilla.org/zh-CN ...

  4. 如何让DIV相对于body水平和垂直居中

    我们在设计页面的时候,经常要把DIV居中显示,而且是相对页面窗口水平和垂直方向居中显示,如让登录窗口居中显示.我们传统解决的办法是用纯CSS来让DIV居中.在本文中,我将给大家讲述如何用CSS和jQu ...

  5. WPF中的数据模板(DataTemplate)(转)

    原文地址 http://www.cnblogs.com/zhouyinhui/archive/2007/03/30/694388.html WPF中的数据模板(DataTemplate)        ...

  6. 微信公共服务平台开发(.Net 的实现)10-------地理位置

    微信公共平台中涉及到地理位置的有两种情况:       第一.我发送一个自选的地理位置给微信,然后微信可以自动反馈响应的信息.       第二.让微信获取我们GPS定位地址位置,反馈响应的信息. 首 ...

  7. Center OS mongodb安装

    一.下载        1.#cd /usr/local/src     2.#wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2. ...

  8. leetcode二分查找问题整理

    自从做完leetcode上的三道关于二分查找的题后,我觉得它是比链表找环还恶心的题,首先能写出bugfree代码的人就不多,而且可以有各种变形,适合面试的时候不断挑战面试者,一个程序猿写代码解决问题的 ...

  9. ios上比较好用的Cydia插件

    1.iFile查看系统文件 2.KuaiDial归属地数据库 3.KuaiDial电话拨号助手 4.搜狗输入法 Photo Editor 房贷计算器

  10. [原创]SSIS-执行包任务调用子包且子包读取父包变量

    背景:       有时候需要将一个个开发好的独立的ETL包串接起来形成一个独立而庞大的包,如:每家分公司都开发不同的ETL包,最后使用执行包任务来将这些分公司的包给串联起来形成一个独立而完整运行的E ...