一、文件夹的操作
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. C# 使用ping命令

    方法一:调用cmd 的ping命令 private static string CmdPing(string strIp) { Process p = new Process(); p.StartIn ...

  2. 6.开放-关闭原则(Open-Close Principle)

    1.定义 一个软件实体(如类.模块.函数)应当对扩展开放,对修改关闭. 2.定义解读 在项目开发的时候,都不能指望需求是确定不变化的,大部分情况下,需求是变化的.那么如何应对需求变化的情况?这就是开放 ...

  3. Using Eclipse With CloudStack

    As part of switching to Apache Maven for building CloudStack, the .classpath and .project files used ...

  4. 利用FlashPaper实现类似百度文库功能

    最近需要实现一个类似百度文库的功能,在Google上淘了一段时间,发现FlashPaper还算能够不错的实现此需求. 首先讲下思路: 1>安装FlashPaper: 2>利用java代码将 ...

  5. CANBus Determining Network Baud Rate, Automatic bit-rate detection

    http://www.canbushack.com/blog/index.php?title=determining-network-baud-rate Determining Network Bau ...

  6. Codeforces Good Bye 2015 C. New Year and Domino 前缀和

    C. New Year and Domino 题目连接: http://www.codeforces.com/contest/611/problem/C Description They say &q ...

  7. 如何进行js动态生成option?如何实现二级连动?

    何为二级连动? 首先要明白什么是二级连动!顾名思义,就是一个动,另外一个也跟着一起动 看下面的例子: 这里有一个“市级”的选择列表框,还有一个“县级”的选择列表框,如果“市级”的选择列表框中的值发现变 ...

  8. Java模式(适配器模式)

    今天看了下Java中的适配器模式,下面就来小做下总结和谈谈感想,以便日后使用. 首先,先来先讲讲适配器.适配就是由“源”到“目标”的适配,而其中链接两者的关系就是适配器.它负责把“源”过度到“目标”. ...

  9. PS拾色器(前景色背景色)快捷键

    快捷键 I 是拾色器 X 是前后色切换

  10. careercup-高等难度 18.6

    18.6 设计一个算法,给定10亿个数字,找出最小的100万个数字.假定计算机内存足以容纳全部10亿个数字. 解法: 方法1:排序 按升序排序所有的元素,然后取出前100万个数,时间复杂度为O(nlo ...