怎么判断工程目录下是否存在某个文件,若存在就删掉,
谢谢指教!!

解决方案 »

  1.   

    Function ReportFileStatus(filespec)
       Dim fso, msg
       Set fso = CreateObject("Scripting.FileSystemObject")
       If (fso.FileExists(filespec)) Then
          msg = filespec & " exists."
       Else
          msg = filespec & " doesn't exist."
       End If
       ReportFileStatus = msg
    End Function
      

  2.   

    判断文件、文件夹是否存在:
       '返回布尔值:True 存在,False 不存在,filername 文件名
       Function FileExist(filename As String) 
       Dim Fso As New FileSystemObject
       If Fso.FileExists(filename) = True Then
       FileExist = True
       Else
       FileExist = False
       End If
       Set Fso = Nothing
       End Function
       '返回布尔值:True 存在,False 不存在,foldername 文件夹
       Function FolderExist(foldername As String)
       Dim Fso As New FileSystemObject
       If Fso.FolderExists(foldername) = True Then
       FolderExist = True
       Else
       FolderExist = False
       End If
       Set Fso = Nothing
       End Function关于删除可以使用 SHFileOperation 实现.......
      

  3.   

    楼上的,谢谢了,
    能不能简单一点的语句,我的目的是,判断我的工程目录下有没有一个为xuexi.txt的文件,有的话就删掉这个文件,我想问 的是这个判断语句如何写?
      

  4.   

    if dir(App.Path & "\xuexi.txt") <> "" then kill App.Path & "\xuexi.txt"
      

  5.   

    Private Declare Function GetSystemDirectory _
            Lib "kernel32" Alias "GetSystemDirectoryA" _
            (ByVal lpBuffer As String, ByVal nSize As _
            Long) As Long
            
    Sub main()
     Dim astr As String
        Dim l As Long
        
        astr = String(256, 0)    l = GetSystemDirectory(astr, Len(astr))
        If l Then
            dirstring = Left$(astr, l)
        End If
    If Dir(dirstring & "\cx.txt") <> "" Then Kill (dirstring & "\cx.txt")End Sub给段代码看看,我看了楼上的兄弟给的代码调试通过的,呵呵~~~!!
    检查系统目录下如果有cx.txt那么删除它
    他的办法确实简洁实用哦,你要用只要修"改路"径就OK了!!
    以上代码在VB6.0 windows 2000 sp4上测试通过