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模块 ...
随机推荐
- iisapp 命令 弹出 iisschlp.wsc [88,25] 属性值无效 progid
iisapp 命令 弹出 iisschlp.wsc [88,25] 属性值无效 progid 在执行iisapp.vbs时,可能会提示如下错误:Windows Script Component - f ...
- C#以及Oracle中的上取整、下取整方法
1.C#中: 上取整——Math.Ceiling(Double),即返回大于或等于指定双精度浮点数的最大整数(也可称为取天板值): eg: Math.Ceiling(1.01)=2; Ma ...
- C++ 中 int,char*,string,CString之间相互转换-整理
<多字符集下> #include <string> //使用C++标准库的string类时, 定义时 std::string str; using namespace std; ...
- Flex 舞台背景渐变
<?xml version="1.0" encoding="utf-8"?><s:Application xmlns:fx="htt ...
- sql 将一个表中的数据插入到另一个表中
列名不一定要相同,只要你在HH中列出要插入列的列表跟select from mm表中的选择的列的列表一一对应就可以了,当然两边的数据类型应该是兼容的. 比如:insert into h ...
- Ubuntu12.10 下搭建基于KVM-QEMU的虚拟机环境(十六)
今天我们继续实验Bridge方式的网络配置. Bridge的逻辑原理图如下: 上图中的“br0”就充当了一个桥的作用,主机上的物理网口eth0等根据需要加入到这个桥里面,所有虚拟机要跟外界通信都通过这 ...
- Matrix对bitmap的一些操作
本篇文章是对使用Matrix对bitmap的旋转与镜像水平垂直翻转进行了详细的分析介绍,需要的朋友参考下 Bitmap convert(Bitmap a, int width, int height ...
- 连接SQLServer时提示“但是在登录前的握手期间发生错误。 (provider: SSL Provider, error: 0 - 等待的操作过时”解决办法
解决:"已成功与服务器建立连接,但是在登录前的握手期间发生错误. (provider: SSL Provider, error: 0 - 等待的操作过时" 官方问题介绍:http: ...
- UVALive 4192 Close Enough Computations 水题
Close Enough Computations 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge& ...
- Android 多级树形菜单
在Android里要实现树形菜单,都是用ExpandableList(也有高手自己继承ListView或者LinearLayout来做),但是ExpandableList一般只能实现2级树形菜单... ...