C# 可视化读取文件、文件夹
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);
Stay hungry,stay foolish.