2010-08-28 107 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参考如果不可用。

相关问题