2010-08-28 108 views

回答

0

有在.NET 4.0中引入的EnumerateFiles方法。如果沒有,你可以使用GetFiles方法,但要注意這個方法返回一個表示匹配文件名的字符串數組,它可能會阻塞很長一段時間。

1
Dim di As New DirectoryInfo("c:\") 
    Dim files() As FileInfo = di.GetFiles("*.abc", SearchOption.AllDirectories) 
+0

我試圖代碼,但錯誤說 沒有定義的DirectoryInfo 文件信息不定義 另外,我怎麼能路徑存儲到一個變量 – 2010-08-29 08:54:09

+0

兩種這些類型都在System.IO,所以你需要把在代碼文件的頂部導入System.IO語句,如果您還沒有,可以添加對它的引用。 – Peter 2010-08-29 17:31:01

0

嗯,這很尷尬,但這似乎之前爲我工作,也許你可以試試

If System.IO.File.Exists(txtName.Text) Then 
     MsgBox("Match not found") 
    Else 
     MsgBox("Match found") 
End If 

更新

這一個工程

Directory.SetCurrentDirectory(My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\WinVault") 
If Not System.IO.File.Exists(txtName.Text & ".wv") Then 
    btnSave.Enabled = True 
Else 
    btnSave.Enabled = False 
    'Balloon tip 
    bTipControl = txtName 
    bTipCaption = "Vault Name" 
    bTipText = VAULT_NAME_EXIST 
    bTip_Show() 
End If 

當然,請確保您輸入System.IO或廣告d參考如果不可用。

相關問題