C#中获取文件夹地址、获取文件地址、获取文件夹中的某种类型文件集合、获取某文件中某种类型文件数量操作方法!
2016-06-22 00:35
393 查看
C#中获取文件夹地址、获取文件地址、获取文件夹中的某种类型文件集合、获取某文件中某种类型文件数量操作方法!
1.获取文件夹地址
2.获取某个文件地址
3.获取文件夹中某类文件
4.获取某文件中某种类型文件数量
5.获取文件名/拓展名
本人正在学习中,其他方法有待后续更新。。。
1.获取文件夹地址
//获取文件夹地址 FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "The Description Of The Dialog"; if (fbd.ShowDialog() == DialogResult.OK) { string path = fbd.SelectedPath; ******* ******* }
2.获取某个文件地址
//获取某个文件地址 OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "(FileTypeName)|(*.YourFileType)"; ofd.Title = "Your File Dialog Title"; if (ofd.ShowDialog() == DialogResult.OK) { string path = ofd.FileName; ******* ******* }
3.获取文件夹中某类文件
//获取文件夹中某类文件集合 DirectoryInfo directoryInfo = new DirectoryInfo(PicturePosTextBox.Text); FileInfo[] fileInfo = directoryInfo.GetFiles("*.jpg"); foreach (FileInfo info in fileInfo) string fullName = info.FullName; ******* *******
4.获取某文件中某种类型文件数量
//获取某文件中某种类型文件数量 string fileType = "*.YourFileType"; string directoryPath = "********"; int fileNum = Directory.GetFiles(directoryPath, fileType).Length;
5.获取文件名/拓展名
string fileFullName = @"C:\Program Files\Microsoft Visual Studio 14.0\test.jpg"; string filename = Path.GetFileName(fileFullName ); //文件名"test.jpg" string extension = Path.GetExtension(fileFullName );//扩展名 ".aspxjpg" string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileFullName );// 没有扩展名 "test"
本人正在学习中,其他方法有待后续更新。。。
相关文章推荐