MS文件与路径的一些方法记录
2014-12-29 14:35
204 查看
一,路径相关
二 获取文件夹下所有文件名
2.1使用DirectoryInfo
2.2 使用Directory
String path1 = System.IO.Directory.GetCurrentDirectory(); MessageBox.Show("获取应用程序的当前工作目录:" + path1); //获取程序的基目录。 String path2 = System.AppDomain.CurrentDomain.BaseDirectory; MessageBox.Show("获取程序的基目录:" + path2); //获取和设置包括该应用程序的目录的名称。 String path3 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; MessageBox.Show("获取和设置包括该应用程序的目录的名称:" + path3); //获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。 String path4 = System.Windows.Forms.Application.StartupPath; MessageBox.Show("获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称:" + path4); //获取启动了应用程序的可执行文件的路径及文件名 String path5 = System.Windows.Forms.Application.ExecutablePath; MessageBox.Show("获取启动了应用程序的可执行文件的路径及文件名:" + path5);
二 获取文件夹下所有文件名
2.1使用DirectoryInfo
using System.IO;//DirectoryInfo using System.Windows.Forms; //Application DirectoryInfo dzong = new DirectoryInfo(Application.StartupPath); foreach (FileInfo fi in dzong.GetFiles()) { if (fi.Extension.Equals(".doc")) { cbox.Items.Add(fi.Name.Replace(".doc", ""));//cbox 是标准combox } }
2.2 使用Directory
using System.IO;//Directory foreach (string f in Directory.GetFiles(Application.StartupPath , "*.doc")) { string[] str = f.Split('\\'); cb_SelectSkin.Items.Add((str[str.Count() - 1]).Replace(".doc", ""));//去掉文件类型 }
相关文章推荐
- 文件路径及管理的一些方法
- Android中调用系统摄像并且保存到指定位置的一些问题&Uri转文件路径方法
- 记录小方法-获取文件路径Fileopen
- 记录一下,根据文件路径获取到其所在目录的方法
- 递归的一些方法使用:深度遍历路径中的所有文件和目录,删除一个有文件的文件夹
- 文件路径的一些方法
- qmake.exe是在Qt安装编译时生成的,里面内嵌了Qt相关的一些路径(最简单的方法是保持一样的安装路径,最方便的办法是设置qt.conf文件)
- 一些软件存储记录的文件和解密方法
- 如何简单的下载一些小文件并保存在一个路径中(有些方法进行了封装)
- 1次插入多条记录的方法(SQL语句,在MS SQL Server 2000查询分析器中执行成功)
- 更改IE收藏夹、历史记录存放路径的方法
- 前段时间做文件上传控件,找到些关于ASP.NET中文件操作的方法,顺便记录下来,和大家共享。
- mssql server 存储过程里,bulk insert table from '路径+文件',路径固定,文件名不固定的实现方法
- 对路径XXX的访问被拒绝(文件操作权限)的解决方法
- (转)对路径"xxxxx"的访问被拒绝(文件操作权限)的解决方法
- C#隐藏文件下载路径的方法
- 重装MS SQL Server 2000前必须彻底删除原安装文件的方法
- Path.Combine (合并两个路径字符串)方法的一些使用细节
- VS2005下调用MS Speech API 5.1, 在添加“sphelper.h”头文件出现的问题,及解决方法
- 一个很有用的方法,可用根据一个类文件找到他的路径