if dir("filename")<>"" then

解决方案 »

  1.   

    to Jneu(沧海桑田) 
    如果字符串中包含无效字符串,dir无法工作
      

  2.   

    Public Declare Function PathFileExists Lib "shlwapi.dll" Alias "PathFileExistsA" (ByVal lpszPath As String) As Long
    Public Declare Function PathIsDirectory Lib "shlwapi.dll" Alias "PathIsDirectoryA" (ByVal lpszPath As String) As LongIf PathFileExists(<文件名>) <> 0 And PathIsDirectory(<文件名>) = 0 Then 文件存在。PathFileExists 判断文件、目录是否存在,PathIsDirectory 判断目录是否存在。返回非零值表示存在。上面的判断语句判断<文件名>是否存在,并且确认它不是目录。系统兼容性:
    Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with Internet Explorer 4.0 or later). 
    Windows 95/98/Me: Requires Windows 98 (or Windows 95 with Internet Explorer 4.0 or later).