【发布时间】:2011-01-27 11:40:32
【问题描述】:
我有一些代码是在我开始之前编写的(听起来像是为 The Daily WTF 提交的!)它加载了一个用于处理的 xml 文件(Throw 行已被简化以隐藏罪魁祸首的身份,否则它逐字逐句)。
Try
docData.Load(strPath)
Catch oError As Exception
Throw New Exception("There is a load or parse error in the xml")
End Try
oFileInfo = New FileInfo(strPath)
strFileName = oFileInfo.FullName
oFileInfo = Nothing
strFileName在方法中再次使用,传递给另一个方法
strPath在方法中再次使用,删除文件时
来自MSDN:
FullName:获取目录或文件的完整路径。 (继承自FileSystemInfo。)
当然,这只是简单地返回 strPath 中已有的内容,并且可以用简单的替换
strFileName = strPath
或者甚至完全取消 strFileName 并始终使用 strPath。
或者我错过了什么? FileInfo.FullName 还会做其他事情吗?
我确实认为这是一个文件存在检查,但这已经被 XmlDocument.Load 周围的 Try...Catch 处理了,此外,File.Exists(strPath) 会简单得多。
【问题讨论】:
标签: vb.net .net fileinfo system.io.fileinfo