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模块 ...
随机推荐
- 自定义Template,向其中添加新的panel
参考网站:https://www.devexpress.com/Support/Center/Example/Details/E2690 思路: 新建一个DefaultTemplate: ...
- Microsoft SQL Server 2008 基本安装说明
Microsoft SQL Server 2008 基本安装说明 安装SQL2008的过程与SQL2005的程序基本一样,只不过在安装的过程中部分选项有所改变,当然如果只熟悉SQL2000安装的同志来 ...
- SAP Connector 3.0 .Net 开发
在VS2010中使用控制台应用程序使用SAP Connector 3.0开发时,当程序运行到实例化RfcConfigParameters时报错 (RfcConfigParametersrefcon = ...
- Codeforces Gym 100803D Space Golf 物理题
Space Golf 题目连接: http://codeforces.com/gym/100803/attachments Description You surely have never hear ...
- 浅析C#基于TCP协议的SCOKET通信
TCP协议是一个基本的网络协议,基本上所有的网络服务都是基于TCP协议的,如HTTP,FTP等等,所以要了解网络编程就必须了解基于TCP协议的编程.然而TCP协议是一个庞杂的体系,要彻底的弄清楚它的实 ...
- vs 设置生成的实体为复数
- iOS开发——动画编程Swift篇&(四)CABasicAnimation动画
CABasicAnimation动画 //CABasicAnimation-不透明度 @IBAction func cabOpacity() { let animation = CABasicAnim ...
- 虚拟机VMware 9安装苹果MAC OSX 10.8图文教程
前些天虚拟机VMware Workstation 9出来,相信大家都已经熟悉VM9了,至于MAC OSX 10.8系统,那也是出来一段时间了,本篇文章就是来讲解VMware Workstation 9 ...
- Cocos2d-x内存管理研究<二>
http://hi.baidu.com/tzkt623/item/46a26805adf7e938a3332a04 上一篇我们讲了内核是如何将指针加入管理类进行管理.这次我将分析一下内核是如何自动 ...
- Sharepoint 列表ItemAdding事件判断文件类型、获取当前上传的文件
using System; using System.Security.Permissions; using Microsoft.SharePoint; using Microsoft.SharePo ...