文件流基础知识(后面补)

Fileinfo是读取文件属性
DirectoryInfo读取文件夹属性

获取路径下全部文件夹 点击查看代码
string foldPath = ""; FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.Description = "请选择文件路径"; dialog.SelectedPath = "";
			dialog.RootFolder = Environment.SpecialFolder.MyComputer;//打开就是我的电脑
			if (dialog.ShowDialog() == DialogResult.OK)
			{
				Pic_Use.RootPath = dialog.SelectedPath;
				DirectoryInfo directoryInfo = new DirectoryInfo(Pic_Use.RootPath);
				DirectoryInfo[] directoryInfos = directoryInfo.GetDirectories();//到这就结束了
				string path = directoryInfos[0].FullName;
				string[] temp = path.Split('\\');
				string temptime = temp[temp.Length];
				Pic_Use.Path_TimeIndexNow = temptime;

			}
获取文件夹下全部类型文件名称 点击查看代码
List<string> GetAllFileNames(string path, string pattern = "*")
		{
			DirectoryInfo folder = new DirectoryInfo(path);

			List<string> fileNames = new List<string>();

			foreach (FileInfo file in folder.GetFiles(pattern))
			{
				fileNames.Add(file.Name);
			}
			return fileNames;
		}
posted @ 2021-11-17 14:55  你的代码能改变世界吗  阅读(16)  评论(0编辑  收藏  举报