本文介绍了存在快速检查文件的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我使用以下代码但不确定我的代码是否以最佳速度运行;两次扫描目录?有没有更有效的方法来执行此操作?检查是否存在JPG或PNG。非常感谢。 我的尝试:
Hi I am using the following code but not sure if my code runs at best speed; two scans of the directory? Any more efficient way to execute this? Checks to see if a JPG or PNG exists. Many thanks. What I have tried:
<pre> 'Check if jpg or png exist and then use this image If fd3 <> "" Then fd3 = Path.GetFileNameWithoutExtension(fd3) & ".jpg" loc_a = locpath + fd3 If Dir(loc_a) <> "" Then im = loc_a Else fd3 = Path.GetFileNameWithoutExtension(fd3) & ".png" loc_a = locpath + fd3 If Dir(loc_a) <> "" Then im = loc_a End If End If End If推荐答案
尝试: Dim basePath As String = locpath & Path.GetFileNameWithoutExtension(fd3) If File.Exists(basePath & ".jpg") Then im = basePath & ".jpg" ElseIf File.Exists(basePath & ".png") Then im = basePath & ".png" End If
更多推荐
存在快速检查文件的方法
发布评论