在VB中,
1。知道文件的路径,我怎么确认此文件是否存在?
2。如果存在,我怎么知道它是否可写?
3。如果可写,我怎么知道它是否正被其他应用程序打开?

解决方案 »

  1.   

    1 If Dir(yourFilePathName)="" Then MSGBox "No Such File Found!"2 
        Dim fs, f, r
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFile(fs.GetFileName(yourFilePathName))
        If f.attributes and 1 Then MSGBox "The File is ReadOnly!"3
        尝试一下改名:
        On Error Goto ErrorHandler
        f.Name = "myTempName"
        f.Name = yourFilePathName
        Exit Sub    ErrorHandler:
        MSGBox "The File is Opened by Other User!"
      

  2.   

    1、
    Dim fso, msg
    filespec=inputbox("输入你要判断存在的文件路径")
    Set fso = CreateObject("Scripting.FileSystemObject")
    if (fso.FileExists("d:\b1.txt")) Then
        msgbox filespec & " 存在。"
    Else
        msgbox filespec & " 不存在。"
    End If2、
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.Getfile(inputbox("输入文件路径"))
    if f.attributes=1 then msgbox "该文件只读"3、同意楼上的
      

  3.   

    笔误,更正一下1:
    filespec=inputbox("输入你要判断存在的文件路径")
    Set fso = CreateObject("Scripting.FileSystemObject")
    if (fso.FileExists(filespec)) Then
        msgbox filespec & " 存在。"
    Else
        msgbox filespec & " 不存在。"
    End If