博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IO Directory DirectoryInfo
阅读量:6924 次
发布时间:2019-06-27

本文共 914 字,大约阅读时间需要 3 分钟。

1.Directory和DirectoryInfo这两个类都是对文件进行操作,但Directory是静态类,所以它的执行效率会更高一点。

 

2.对文件操作。我们可以这样认为,Directory和directoryInfo都是一样的,只是表现形式不一样。

 

3.获取目录的文件名称或者是文件夹名称。

代码如下;

ExpandedBlockStart.gif
View Code
 1 
  
string
 path 
=
 
@"
c:\wtqCreate
"
;
 2 
            
string
 pathTxt 
=
 path 
+
 
@"
\my.txt
"
;
 3 
            
if
 (
!
Directory.Exists(path))
 4 
            {
 5 
 6 
                Directory.CreateDirectory(path);
 7 
                
using
 (StreamWriter sw 
=
 File.CreateText(pathTxt))
 8 
                {
 9 
                    sw.WriteLine(
"
my name is wtq
"
);
10 
                    sw.WriteLine(
"
and what's your name
"
);
11 
                    sw.WriteLine(
"
my name is wwttqq
"
);
12 
                    sw.WriteLine(
"
I Can do everyThing
"
);
13 
                }
14 
            }
15 
           DirectoryInfo di 
=
 
new
 DirectoryInfo(path);
16 
           var fp 
=
 di.GetFileSystemInfos();
17 
            
foreach
(var f 
in
 fp)
18 
            {
19 
                Console.WriteLine(
"
简称{0},全名{1}
"
,f.Name,f.FullName);
20 
            }
21 
22 
            var dp 
=
 Directory.GetFileSystemEntries(path);
23 
            
foreach
 (var item 
in
 dp)
24 
            {
25 
                Console.WriteLine(
"
获取目录中的文件夹和文件的名称
"
);
26 
                Console.WriteLine(item);
27 
            }
28 
            Console.ReadLine();

转载地址:http://nacjl.baihongyu.com/

你可能感兴趣的文章
Linux系统之根文件系统
查看>>
Perl入门(一)Perl的基本类型及运算符
查看>>
cgic程序的编写遇到的问题
查看>>
windows server 2008 软raid的方法
查看>>
我的友情链接
查看>>
利用冗余实现企业局域网的高可用性
查看>>
知识点总结报告 1.26
查看>>
HDU 2243 AC自动机+DP+矩阵
查看>>
IPv6 over Frame Relay – Point-to-Point
查看>>
centos6.4安装配置lamp环境
查看>>
sql优化-查询语句使用“?”
查看>>
struts2 标签 验证和国际化
查看>>
10. JavaSE-子类实例化过程 & 构造方法间调用
查看>>
虚拟集群通过ip或mac查找虚拟机名称方法
查看>>
nacos作为配置中心
查看>>
Objective-C 对象复制(深复制/浅复制)
查看>>
keepalived+nginx实现nginx高可用
查看>>
OCR SDK开发者平台
查看>>
【SMTP简单邮件协议的服务配置】
查看>>
20145328 《Java程序设计》实验三实验报告
查看>>