1、讀取E:\1.txt中的字串,txt中內容一共3行,如下:
PipeWeldingJoint
Expressions
tsOutputData
2、讀取第一行PipeWeldingJoint,在D:\workdir及其子檔案夾下搜索含有該字串的檔案
3、復制檔案到指定目錄E:\
uj5u.com熱心網友回復:
雖然你給了100分,我還是要說:苦力活自己做,什么地方有錯了再來問。uj5u.com熱心網友回復:
難度不大,就是要實作單程序的話難度就大了,檔案窮舉比較費事,做成幾個函式程序+遞回做就好些,別的沒什么了,留給勤快人接這活吧uj5u.com熱心網友回復:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If My.Computer.FileSystem.FileExists(TextBox2.Text & "\devtest.txt") = False Then
MsgBox("could not find devtest file")
Return
End If
str3 = RichTextBox1.Text
str3 = sb(str3)
If str3 = "" Then
MsgBox("the unit path is null", , "error")
Return
End
End If
If TextBox2.Text = "" Then
TextBox2.Text = "E:\pr_data"
End If
If str7 = "" Then
str7 = "E:\pr_data"
End If
If xml_file = True Then
search_xml = New Threading.Thread(AddressOf xml)
search_xml.Start()
Else
End If
Dim n As Integer = 0
Dim txt As IO.StreamReader = New IO.StreamReader(str7 & "\devtest.txt", System.Text.Encoding.Default)
Do Until txt.EndOfStream
n = n + 1
ReDim Preserve str(n) '陣列從1開始
str(n) = txt.ReadLine()
Loop
txt.Close()
Dim fgs As New System.IO.FileInfo(str7 & "\devtest.txt")
If fgs.Length = 3 Then
MsgBox("The devtest.txt is a null file.")
Return
End If
'讀取網頁
Dim MyClient As Net.WebClient = New Net.WebClient
Dim MyReader As New System.IO.StreamReader(MyClient.OpenRead("file:///" & str3 & "/dt/runs/run1/logs/results/devtestMasterResults.xml"), System.Text.Encoding.UTF8)
Dim MyWebCode As String = MyReader.ReadToEnd
Dim strline2 As String
strline2 = MyWebCode
MyReader.Close()
'讀取資料
Dim a, b, d, x, y, m, z, r As Integer
Dim g, h, o, c As String
g = Nothing
Dim k, p As String
h = Nothing
o = Nothing
r = 1
a = 0
For r = 1 To n Step 1
strline = str(r)
a = InStr(strline2, str(r))
'MsgBox(str(r))
If a <> 0 Then
b = InStr(a, strline2, " id=")
c = Mid(strline2, a, b - a - 1)
'MsgBox(c)
'MsgBox(strline)
If c = strline Then
Do Until g <> ""
strline2 = MyWebCode
j = InStr(strline2, str(r))
If j Then
d = InStr(j, strline2, "relToThisFile=")
x = InStr(d, strline2, "name=")
y = InStr(d, strline2, "><")
g = Mid(strline2, d + 18, x - d - 20)
h = Mid(strline2, x + 6, y - x - 7)
strline2 = MyWebCode
m = InStr(y, strline2, "name=")
z = InStr(m, strline2, "><")
o = Mid(strline2, m + 6, z - m - 7)
End If
Loop
'MsgBox(str3)
k = str3 & "\dt\runs\run1\logs\" & g & "/" & h
p = str3 & "\dt\runs\run1\logs\" & g & "/" & o
'MsgBox(o)
My.Computer.FileSystem.CopyFile(p, TextBox2.Text & "\" & o) 'copy .syslog
My.Computer.FileSystem.CopyFile(k, TextBox2.Text & "\" & h) 'copy .bad
g = ""
Else
End If
Else
inexistence(r) = str(r)
Dim aaa As Integer
For aaa = 1 To r Step 1
My.Computer.FileSystem.WriteAllText("C:\Temp\temp.txt", inexistence(aaa) & vbCrLf, True)
Next
Process.Start("C:\Temp\temp.txt")
End If
Next
Dim filenumber As Integer = GetFileNum(TextBox2.Text)
Dim seqnumber As Integer = n * 2 + 1
If filenumber = seqnumber Then
MsgBox("Done")
ElseIf filenumber < seqnumber Then
MsgBox("Some file can't copy to " & TextBox2.Text, , "Error")
End If
End Sub
uj5u.com熱心網友回復:
我上面的代碼是在一個內嵌的HTML中需找字串,然后用這個字串尋找檔案,copy到指定目錄現在只是將問題簡化了,上面代碼,已經能夠讀取html中的字串了。我想先用txt讀字串,學習下如何在某個檔案(含子檔案)下面搜索含有該字串的檔案。這個我之前沒學過,自學了一段時間,對一些索引演算法還是不懂,大神求幫助啊!都困擾我好長時間了
制作的小工具“FIND”就是尋找這些軟體的,其他功能都是實作了就剩下這一個,受夠了

uj5u.com熱心網友回復:
dir函式就可以窮舉指定檔案夾下的檔案了第一次呼叫時加路徑 Dir(Path)
然后呼叫的時候用空引數 Dir("")
每次呼叫回傳一個Path下的檔案或者檔案夾,直到回傳值為“”時結束
如果回傳的是檔案夾,就需要遞回下一級
uj5u.com熱心網友回復:
.Net 不是有現成的 My.Computer.FileSystem.FindInFiles() 可用嗎。uj5u.com熱心網友回復:
C:\>findstr /?在檔案中尋找字串。
FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/F:file]
[/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]]
strings [[drive:][path]filename[ ...]]
/B 在一行的開始配對模式。
/E 在一行的結尾配對模式。
/L 按字使用搜索字串。
/R 將搜索字串作為一般運算式使用。
/S 在當前目錄和所有子目錄中搜索匹配檔案。
/I 指定搜索不分大小寫。
/X 列印完全匹配的行。
/V 只列印不包含匹配的行。
/N 在匹配的每行前列印行數。
/M 如果檔案含有匹配項,只列印其檔案名。
/O 在每個匹配行前列印字符偏移量。
/P 忽略有不可列印字符的檔案。
/OFF[LINE] 不跳過帶有脫機屬性集的檔案。
/A:attr 指定有十六進位數字的顏色屬性。請見 "color /?"
/F:file 從指定檔案讀檔案串列 (/ 代表控制臺)。
/C:string 使用指定字串作為文字搜索字串。
/G:file 從指定的檔案獲得搜索字串。 (/ 代表控制臺)。
/D:dir 查找以分號為分隔符的目錄串列
strings 要查找的文字。
[drive:][path]filename
指定要查找的檔案。
除非引數有 /C 前綴,請使用空格隔開搜索字串。
例如: 'FINDSTR "hello there" x.y' 在檔案 x.y 中尋找 "hello" 或
"there"。'FINDSTR /C:"hello there" x.y' 檔案 x.y 尋找
"hello there"。
一般運算式的快速參考:
. 通配符: 任何字符
* 重復: 以前字符或類別出現零或零以上次數
^ 行位置: 行的開始
$ 行位置: 行的終點
[class] 字符類別: 任何在字符集中的字符
[^class] 補字符類別: 任何不在字符集中的字符
[x-y] 范圍: 在指定范圍內的任何字符
\x Escape: 元字符 x 的文字用法
\<xyz 字位置: 字的開始
xyz\> 字位置: 字的結束
有關 FINDSTR 常見表達法的詳細情況,請見聯機命令參考。
uj5u.com熱心網友回復:
貌似是字串的模式匹配的內容。轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/89633.html
標籤:VB基礎類
