将字符串数组转换为c#中的fileinfo数组 [英] convert string array to fileinfo array in c#
本文介绍了将字符串数组转换为c#中的fileinfo数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.CheckFileExists = true;
openFileDialog.AddExtension = true;
openFileDialog.Multiselect = true;
openFileDialog.Filter = "PDF files (*.pdf)|*.pdf";
DialogResult result = openFileDialog.ShowDialog();
if (result == DialogResult.OK)
{
string[] files = openFileDialog.FileNames;
}
这个我想将字符串数组转换为fileinfo array.fileinfo数组对于简单访问pdffile属性非常有用文件名,文件路径,扩展名,大小,文件内容。
我的字符串数组如
in this i want to convert string array to fileinfo array.fileinfo array is useful for simple access pdffile properties like filename,file path,extension,size,content of file.
my string array like
string[] files = openFileDialog.FileNames;
请帮帮我。
pls help me.
推荐答案
试试这个;
Try this;
var fileInfos = openFileDialog.FileNames.Select(x => new FileInfo(x)).ToArray();
请记住导入 System.Linq
。
希望这会有所帮助,
Fredrik
Remember to import System.Linq
.
Hope this helps,
Fredrik
这篇关于将字符串数组转换为c#中的fileinfo数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文