问题描述
这是代码:
FileInfo[] flist = d.GetFiles();
if (flist.GetLength(0) > 0)
{
foreach (FileInfo txf in flist)
{
string fn = txf.FullName + txf.Extension;
}
}
如果我只做全名,它将给我目录+文件名,但不带扩展名。
如果我正在这样做:字符串fn = txf.FullName + txf.Extension;扩展名是空的
If i'm doing only fullname it will give me the directory+file name but without the Extension.And if i'm doing it: string fn = txf.FullName + txf.Extension; Extension is empty ""
例如,我需要使它完整:c:\test.png
否则fn将包含:c: \temp\dir\testing.jpg
I need to get it full like this for exmaple: c:\test.pngOr that fn will contain: c:\temp\dir\testing.jpg
完整目录路径+完整文件名+文件扩展名
Full directory path + full file name + the file name extension
推荐答案
根据, FileInfo
对象的全名
字段包括完整路径,文件名和文件扩展名( FileInfo
从 FileSystemInfo $ c继承
FullName
$ c>)。因此,更像是负责创建这些文件的代码没有附加适当的扩展名(假设 d
是 DirectoryInfo
,而不是其他(也许是自制的)类。
According to the documentation, FullName
field of a FileInfo
object includes full path, file name and file extension (FileInfo
inherits FullName
from FileSystemInfo
). So it is more like the code, which is in charge for creating these files, is not appending the proper extension (Assuming d
is a DirectoryInfo
and not other - maybe homemade - class).
这篇关于如何从FileInfo []获得文件全名的完整目录,包括文件扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!