vb6的filelistbox用法

1.如何刪除目錄下隱藏的檔案?

2.我使用kill刪除顯示的檔案,但是filelistbox沒有馬上顯示那個檔案不見,該怎麼辦?

感謝~!

1 個解答

評分
  • 世賢
    Lv 7
    9 年前
    最佳解答

    一個 FileListBox 和一個 CommandButton

    Option Explicit

    Private Sub Command1_Click()

     If MsgBox(GetPath(File1.Path) & File1.FileName & vbCrLf & "是否刪除此檔案?" & vbCrLf & vbCrLf & myGetAttr(GetPath(File1.Path) & File1.FileName), vbQuestion + vbYesNo) = vbYes Then '顯示路徑及檔名

      Call SetAttr(GetPath(File1.Path) & File1.FileName, vbNormal) '將檔案取消系統、隱藏、唯讀等檔案屬性

      Kill GetPath(File1.Path) & File1.FileName '刪除檔案

      File1.Refresh '重新整理檔案清單

     Else

      Call MsgBox("已取消", vbExclamation)

     End If

    End Sub

    Private Sub Form_Load()

     File1.Path = "D:\" '指定路徑

     File1.Hidden = True '顯示隱藏檔

     File1.Normal = True

     File1.System = False '系統檔

     File1.ReadOnly = False '唯讀檔

    End Sub

    Private Function GetPath(ByVal myStr As String) As String

     GetPath = myStr & IIf(Right(myStr, 1) = "\", "", "\")

    End Function

    Private Function myGetAttr(ByVal myStr As String) As String

     If GetAttr(myStr) And vbSystem Then

      myGetAttr = myGetAttr & IIf(myGetAttr = "", "", "、") & "系統檔"

     End If

     If GetAttr(myStr) And vbHidden Then

      myGetAttr = myGetAttr & IIf(myGetAttr = "", "", "、") & "隱藏檔"

     End If

     If GetAttr(myStr) And vbReadOnly Then

      myGetAttr = myGetAttr & IIf(myGetAttr = "", "", "、") & "唯讀檔"

     End If

    End Function

    參考資料: VB6 and Me
還有問題?馬上發問,尋求解答。