[Visual Basic 6.0] 運用 Drive、Dir、File 物件實作 檔案取與控制範例

摘要:[Visual Basic 6.0] 運用 Drive、Dir、File 物件實作 檔案取與控制範例

[Visual Basic 6.0] 運用 Drive、Dir、File 物件實作 檔案取與控制範例

 

# 功能一:可以下拉式選單選擇磁區 (如 C / D / E 等磁碟區位) 並可選取資料夾、檔案。

 

# 功能二 刪除檔案功能

 

# 功能三 重新命名

 

Dim FileName, NowName, NowFile, Play

Private Sub Command1_Click()
    Command1.Enabled = False
    Kill FileName
    Label1.Caption = NowName & " 檔案已刪除"
    Label2.Caption = NowName & " 檔案已刪除"
    File1.Refresh
    MsgBox "檔案已刪除", , "刪除成功"
End Sub

Private Sub Command2_Click()
    Command2.Enabled = False
    Dim News
    News = InputBox("您將修改的舊檔名為 " & NowName & " 請輸入新的名字")
    
    If Len(News) = 0 Then
        MsgBox "Error:重新命名發生錯誤!", , "錯誤喔~"
    Else
        Name FileName As NowFile & "\" & News
        MsgBox "檔名修改成功!已將 " & NowName & " 檔名成功修改為 " & News
        Label1.Caption = "目前選擇的檔名為:" & News
        Label2.Caption = "目前選擇的路徑為:" & Dir1.Path & "\" & News
        FileName = Dir1.Path & "\" & News
        NowName = News
        Play = NowFile & "\" & News
        File1.Refresh
    End If
End Sub

Private Sub Command3_Click()
    End
End Sub

Private Sub Dir1_Change()
    File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
End Sub

Private Sub File1_Click()
    Command1.Enabled = True
    Command2.Enabled = True
    FileName = Dir1.Path & "\" & File1.FileName
    NowName = File1.FileName
    NowFile = Dir1.Path & "\"
    Play = NowFile & NowName
    Label1.Caption = "目前選擇的檔名為:" & NowName
    Label2.Caption = "目前選擇的路徑為:" & FileName
End Sub

 

 

[Visual Basic 6.0] 檔案取與控制範例.rar

#0xDe 從分享中學習

#Facebook:ProgrammerDe (https://www.facebook.com/MicrosoftDes) 有問題歡迎提問