我有一些代码是在我开始之前编写的(听起来像是为 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别的吗?
我确实认为这是一个文件存在检查,但这已经被Try...Catch周围的人照顾了XmlDocument.Load,而且File.Exists(strPath)会简单得多。