判断在strDir目录下是否存在*.sxl的文件?
若存在*.sxl,
则把文件依次命名为info1.sxl,info2.sxl,info3.sxi,.....请问这种处理能实现吗?或怎么实现呢?

解决方案 »

  1.   

    使用Dir函数可以实现。代码如下:Private Sub Command1_Click()
        Dim iFileCount As Integer
        Dim tmpFile As String
        Dim strDir As String
        
        strDir = App.Path
        If Not (Right(strDir, 1) = "\") Then
            strDir = strDir & "\"
        End If
        
        tmpFile = ""
        iFileCount = 0
        
        '遍历strDir & \.sxl文件的数目,并将文件名赋给tmpFile
        tmpFile = Dir(App.Path & "\*.sxl")
        Do While (Len(tmpFile) <> 0)
            iFileCount = iFileCount + 1
            Name strDir & "\" & tmpFile As strDir & "\info" & iFileCount & ".sxl"   '文件名改名
            tmpFile = Dir()
        Loop
    End Sub
      

  2.   

    上面的代码有错误,重新发一遍:Private Sub Command1_Click()
        Dim iFileCount As Integer
        Dim tmpFile As String
        Dim strDir As String
        
        strDir = App.Path
        If Not (Right(strDir, 1) = "\") Then
            strDir = strDir & "\"
        End If
        
        tmpFile = ""
        iFileCount = 0
        
        '遍历strDir & \.sxl文件的数目,并将文件名赋给tmpFile
        tmpFile = Dir(strDir & "*.sxl")
        Do While (Len(tmpFile) <> 0)
            iFileCount = iFileCount + 1
            Name strDir & tmpFile As strDir & "info" & iFileCount & ".sxl"   '文件名改名
            tmpFile = Dir()
        Loop
    End Sub