更新时间:2022-03-08 19:58:40
如果只想获取文件名,请使用以下代码:
If you want to get the File name only, use the following piece of code:
foreach (string strFiles in aFolderContents)
{
string FileName = System.IO.Path.GetFileName(strFiles);//Gives you file name only
Console.Write(FileName);
}
此处我使用DirectoryInfo,FileInfo提供代码
Here I am providing code using DirectoryInfo, FileInfo
DirectoryInfo dinfo = new DirectoryInfo("c:\\rajesh\\
");
FileInfo[] myfno= dinfo.GetFiles(*.* , SearchOption.AllDirectories);
foreach (FileInfo fno in myfno)
{
MessageBox.Show("FileName" + fno.Name);
MessageBox.Show("Filename with path " + fno.FullName);
MessageBox.Show("Only Path " + fno.DirectoryName);
MessageBox.Show("parent Dir" + fno.DirectoryName);
MessageBox.Show("File Extension" + fno.Extension);
}
谢谢..,
:rose :: rose:
Thanks..,
:rose::rose:
还可以使用FileInfo类来获取文件名.
You can also use FileInfo class to get the file names.
foreach (string strFiles in aFolderContents)
{
FileInfo fi=new FileInfo(strFiles)
Console.WriteLine(fi.Name);
}