黑马程序员 path的常用方法笔记

Path的常用方法:

按照通配符搜索目录下的文件string[] Directory.GetFiles(string path,string searchPattern,SearchOption searchOption)

Path.GetFileNameWithoutExtension(filename):得到文件的文件名(无扩展名)

Path.Combine(string path1,string path2):将两个路径合并

Path.GetFileName(string path):得到文件的文件名

Path.GetExtension(stirng path):得到文件的后缀

Path.GetFullPath(string path):得到文件的全路径

例如:

FolderBrowserDialog dlg=new FolderBrowserDialog();

If(dlg.ShowDialog()!=DialogResult.OK)

{

      Return;

{

String path =dlg.SelectedPath;

String files = Directory.GetFiles(path,”*.txt”,SearchOption.AllDirectories);

posted @ 2012-01-03 14:21  黑马--彭超  阅读(172)  评论(0编辑  收藏  举报