VS-C++ 系列:所有相关C++文章链接.
VS-C# 系列:所有相关C#文章链接.
bat 系列:所有相关bat文章链接.
OpenCV 系列:所有相关OpenCV文章链接.
AD 系列:所有相关文章链接
Keil 系列:所有相关文章链接
Arduino 系列:所有相关Arduino文章链接
Git SVN 系列:所有相关Git SVN文章链接
Linux 系列:所有相关文章链接
python 系列:所有相关文章链接
Raspberry Pi Pico 系列:所有相关文章链接
所有内容均以最小系统调试成功;逐步提供低分源码工程下载!
保证每行代码都经过验证!
如有疑惑,欢迎留言,看见即回;祝好__by Dxg_LC
目录:Dxg_C# 开发小技巧整理集合
1、打开文件/多文件,并获取其路径,文件名,扩展名........Dxg-原创出品,如需转载,请注明出处;序言:
1、以上链接为方便整理查看资料用;伴随博文发布更新,如果有不正确处,感谢指正
2、因本人能力有限若有不正确之处或者相关超链接失效,请于相关文章内提醒@博主;灰常感谢
3、友情提醒1,勿要《一支烟 + 一杯茶 == 一坐一下午》 身体重要,革命本钱;
4、友情提醒2,多喝热水;
5、友情提醒3,听媳妇话+多点时间陪家人;
1、打开文件/多文件,并获取其路径,文件名,扩展名…
OpenFileDialog OpenDlg = new OpenFileDialog();OpenDlg.Filter = "jpg(*.jpg)|*.jpg|bmp(*.bmp)|*.bmp|所有文件(*.*)|*.*;";OpenDlg.Multiselect = true;//允许选择多文件if (OpenDlg.ShowDialog() == DialogResult.OK){//int FilesCount = OpenDlg.FileNames.Count();//选择了多少个文件,可以通过OpenDlg.FileNames[x]获取路径for (int FilesCount = 0; FilesCount < OpenDlg.FileNames.Count(); FilesCount++){//当前选择文件的完整路径string fullPath = OpenDlg.FileNames[FilesCount];//@"D:\\我的桌面\\Pic\\0003.jpg";if (fullPath.Contains(" ")) //去除"文件名中的空格",用下划线代替{string newFullPath = fullPath.Replace(" ", "_");File.Copy(fullPath, fullPath.Replace(" ", "_"));File.Delete(fullPath);fullPath = newFullPath;}Console.WriteLine("完整路径:" + fullPath);//D:\我的桌面\Picstring FilePath = Path.GetDirectoryName(fullPath);Console.WriteLine("路径[不含文件名及后缀]:" + FilePath);//文件名 “0003.aspx”string FileName1 = System.IO.Path.GetFileName(fullPath);Console.WriteLine("文件名:" + FileName1);//扩展名 “.jpg”string Extension = System.IO.Path.GetExtension(fullPath);Console.WriteLine("扩展名/后缀名:" + Extension);// 没有扩展名的文件名 “0003”string FileName2 = System.IO.Path.GetFileNameWithoutExtension(fullPath);Console.WriteLine("文件名[不含扩展名/后缀名]:" + FileName2);}}
Dxg-原创出品,如需转载,请注明出处;
欢迎收藏,点赞;"一键三联"走起,LOL