C#文件基本操作1

感觉和JAVA的也差不多。。。

只是在VS2012的IDE环境下,开发效率要高一些。可能开发效率就是微软的特色吧。。。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 using System.IO;
11 
12 namespace FD
13 {
14     public partial class Form1 : Form
15     {
16         public Form1()
17         {
18             InitializeComponent();
19         }
20 
21         private void button1_Click(object sender, EventArgs e)
22         {
23             if (textBox1.Text == string.Empty)
24             {
25                 MessageBox.Show("file name can't be empty!");
26             }
27             else
28             {
29                 if (File.Exists(textBox1.Text))
30                 {
31                     MessageBox.Show("This file have existed.");
32                 }
33                 else
34                 {
35                     File.Create(textBox1.Text);
36                 }
37             }
38         }
39 
40         private void button2_Click(object sender, EventArgs e)
41         {
42             if (textBox2.Text == string.Empty)
43             {
44                 MessageBox.Show("folder name can't be empty.");
45             }
46             else
47             {
48                 if (Directory.Exists(textBox2.Text))
49                 {
50                     MessageBox.Show("this folder name have exiestd.");
51                 }
52                 else
53                 {
54                     Directory.CreateDirectory(textBox2.Text);
55                 }
56             }
57         }
58 
59         private void button3_Click(object sender, EventArgs e)
60         {
61             if (textBox3.Text == string.Empty)
62             {
63                 MessageBox.Show("empty");
64             }
65             else
66             {
67                 FileInfo finfo = new FileInfo(textBox3.Text);
68                 if (finfo.Exists)
69                 {
70                     MessageBox.Show("exist");
71                 }
72                 else
73                 {
74                     finfo.Create();
75                 }
76             }
77         }
78 
79         private void button4_Click(object sender, EventArgs e)
80         {
81             if (textBox4.Text == string.Empty)
82             {
83                 MessageBox.Show("empty");
84             }
85             else
86             {
87                 DirectoryInfo dinfo = new DirectoryInfo(textBox4.Text);
88                 if (dinfo.Exists)
89                 {
90                     MessageBox.Show("exist");
91                 }
92                 else
93                 {
94                     dinfo.Create();
95                 }
96             }
97         }
98     }
99 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值