您的位置:首页 > 编程语言 > C#

C# 可视化读取文件、文件夹

2016-04-24 21:13 429 查看
OpenFileDialog fd = new OpenFileDialog();
fd.Filter = "txt files (*.txt)|*.txt|All files(*.*)|*.*";
fd.InitialDirectory = Application.StartupPath + "\\Temp\\";
fd.ShowReadOnly = true;
DialogResult r = fd.ShowDialog();
if(r == DialogResult.OK)
{
string all = fd.FileName;
string path = all.Substring(0, all.LastIndexOf("\\") + 1);
string fileName = all.Substring(all.LastIndexOf("\\") + 1, all.LastIndexOf(".") - (all.LastIndexOf("\\") + 1));
string fileExc = all.Substring(all.LastIndexOf(".") + 1, all.Length - all.LastIndexOf(".") - 1);

System.Console.WriteLine("all = {0}", all);
System.Console.WriteLine("path = {0}" ,path);
System.Console.WriteLine("fileName = {0}", fileName);
System.Console.WriteLine("fileExc = {0}",fileExc);
}


FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.ShowNewFolderButton = true;

if (fbd.ShowDialog() == DialogResult.OK)
{
string path = fbd.SelectedPath;
}
else
{
}
获取该路径下的文件目录
string[] dataFiles = Directory.GetFiles(path);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: