VB读取符合文件名条件的文件
例如系统磁盘上存有a2011-01-01.txt,a2011-01-02.txt,a2011-01-03.txt,a2011-01-04.txt,a2011-01-05.txt......
等等一系列文件,我只想读取符合条件的文件,例如我想读出a2011-01-03.txt,如何读取
代码怎么写
[解决办法]
Dim FileName As String FileName = InputBox("请输入文件名:") If Len(FileName) = 0 Then Exit Sub If Len(Dir(FileName)) > 0 Then Dim fs, f, s Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.OpenTextFile(sFile, 1) s = f.readall f.Close: Set f = Nothing: Set fs = Nothing End If Print s
[解决办法]
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'过程功能:'功能描述:Input方式读入文件'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Private Sub btnInput_Click()On Error GoTo errSub strMemo = "" strFile="D:\a2011-01-03.txt" intFileNum = FreeFile(0) Open strFile For Input As #intFileNum Do While Not EOF(intFileNum) Line Input #intFileNum, strMemo txtMemo.Text = txtMemo.Text & strMemo & vbCrLf Loop Close #intFileNum Exit SuberrSub:End Sub
[解决办法]
Private Sub Command1_Click() Dim fs, f, f1, fc, s, s1 Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder("c:\1\1") Set fc = f.Files For Each f1 In fc s = s & f1.Name s = s & " " Next s1 = Split(Trim(s)) MsgBox s1(2) '下标0是第一个文件 End Sub
[解决办法]
Private Sub Command1_Click() Dim fs, f, f1, fc, s, s1 Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder("c:\1\1") Set fc = f.Files For Each f1 In fc s = s & f1.Name s = s & " " Next s1 = Split(Trim(s)) MsgBox s1(2) '下标0是第一个文件 End Sub
[解决办法]
Private Sub Command1_Click() Dim fs, f, f1, fc, s, s1 Set fs = CreateObject("Scripting.FileSystemObject") Set f = fs.GetFolder("c:\1\1") Set fc = f.Files For Each f1 In fc s = s & f1.Name s = s & " " Next s1 = Split(Trim(s)) MsgBox s1(2) '下标0是第一个文件 End Sub