在vb6怎么实现,打开文件后,在list中显示其文件名。

来源:百度知道 编辑:UC知道 时间:2024/06/02 19:04:38
注意,只有文件名,不加后缀。

Public Function GetPathFromFileName(ByVal strFullPath As String, Optional ByVal strSplitor As String = "\") As String
GetPathFromFileName = Left$(strFullPath, InStrRev(strFullPath, strSplitor, , vbTextCompare))
End Function

然后:
Private Sub numOpenFile_Click()

Cg.CancelError = True

On Error GoTo ER
Cg.DialogTitle = "打开Txt文件"
Cg.Filter = "文本文档(*.txt)|*.txt"
Cg.Flags = cdlOFNCreatePrompt + cdlOFNHideReadOnly
Cg.ShowOpen
cgPath = Cg.FileName
list1.additem .GetPathFromFileName(cgPath )
end sub