比如我先判断c:\temp\1_1.txt 这个文件是否存在?
如果存在就打开'目录下有100个txt文件:1_1.txt 1_2.txt ....1_100.txt    For i=1 to 100
    strTemp="c:\temp\"&"1_"&i&".txt" 
      if(?????????)
      Open strTemp For Input As  #1
      ...
      Else
      不做任何事
      End If
      其中?????怎么表达?

解决方案 »

  1.   

    Function FileExists(FileName As String) As Integer
        Dim i As Integer
        On Error Resume Next
        i = Len(Dir$(FileName))
        If Err Or i = 0 Then FileExists = False Else FileExists = True
    End Function
      

  2.   

    If Dir(WinSysDir & "c:\temp\"&"1_"&i&".txt") = ""
      

  3.   

    用File System Object
    里面有Exist函数好久不用,名字可能有不准确~
      

  4.   

    If FileExists(FileName) = True then
    ....
      

  5.   

    If Dir("c:\temp\"&"1_"&i&".txt") = ""
      

  6.   

    For i=1 to 100
        strTemp="c:\temp\"&"1_"&i&".txt" 
          if dir(strTemp)<>"" then
          Open strTemp For Input As  #1
          ...
          Else
          不做任何事
          End If
      

  7.   

    If Dir("c:\temp\"&"1_"&i&".txt" ) = "" Then
            MsgBox "该目录找不到文件!"
        End If
      

  8.   

    看看我写的这个函数是否符合你的要求Function FileExists(FileName As String) As Boolean   '判断固定文件是否存在
    '******************************************
    '* 函数说明:检查 FileName 文件是否存在   *
    '*                                        *
    '* 函数名      返回值   属性值            *
    '* -------------------------------------- *
    '* FileExists  True     文件存在          *
    '*             False    文件不存在        *
    '*                                        *
    '* 变量名      类型     属性值            *
    '* -------------------------------------- *
    '* FileName    String   被检测的文件名    *
    '******************************************
       Dim FileNum As Integer   '文件句柄号
       On Error Resume Next   '错误处理
       FileNum = FreeFile   '获取自由文件句柄
       Open FileName For Input As #FileNum   '打开被检测的文件
       Close #FileNum   '关闭文件
       FileExists = Not (Err <> 0)   '如果文件不存在(Err<>0)则(FileExitsts=False);否则相反
    End Function