(1)覆蓋TXT文件指定某一行內(nèi)容
- // 欲寫(xiě)入的數(shù)據(jù)
- neirong="感謝您使用由《按鍵用戶》制作的腳本"
- // 寫(xiě)入第幾行
- jihang=5
- Text = Plugin.File.ReadFileEx("路徑\文件名.txt")
- txtArray=Split(Text,"|")
- txt=""
- i=0
- Rem z
- If Len(txtArray(i))>=1
- If i=jihang-1
- // 覆蓋
- txt = txt & neirong & vbCrLf
- Else
- txt = txt & txtArray(i) & vbCrLf
- EndIf
- i=i+1
- Goto z
- Else
- If i<=jihang
- MessageBox "少于"&jihang&"行"
- EndScript
- EndIf
- EndIf
- // 刪除舊文檔
- Call Plugin.File.DeleteFile("路徑\文件名.txt")
- // 儲(chǔ)存新文檔
- Call Plugin.File.WriteFileEx("路徑\文件名.txt", txt)
復(fù)制代碼 (2)插入內(nèi)容到TXT文件的指定某一行
- //欲寫(xiě)入的數(shù)據(jù)
- neirong="感謝您使用此腳本"
- //寫(xiě)入第幾行
- jihang=5
- Text = Plugin.File.ReadFileEx("路徑\文件名.txt")
- txtArray=Split(Text,"|")
- txt=""
- i=0
- // 若舊文檔大于jihang行
- If UBound(txtArray)>=1
- For jihang-1
- txt = txt & txtArray(i) & vbCrLf
- i=i+1
- EndFor
- txt = txt & neirong & vbCrLf
- For UBound(txtArray)-(jihang-1)
- txt = txt & txtArray(i) & vbCrLf
- i=i+1
- EndFor
- Else
- // 若舊文檔小于jihang行
- For UBound(txtArray)
- txt = txt & txtArray(i) & vbCrLf
- i=i+1
- EndFor
- txt = txt & neirong & vbCrLf
- EndIf
- // 刪除舊文檔
- Call Plugin.File.DeleteFile("路徑\文件名.txt")
- // 儲(chǔ)存新文檔
- Call Plugin.File.WriteFileEx("路徑\文件名.txt", txt)
復(fù)制代碼 (3)讀取TXT文件指定某一行的第?到第?個(gè)字
- UserVar t=2 "讀出txt第幾行文本"
- UserVar i=5 "從第幾個(gè)字開(kāi)始讀取"
- UserVar O=8 "結(jié)束讀取到第幾個(gè)字"
- Text = Plugin.File.ReadFileEx("路徑\文件名.txt")
- txtArray=Split(Text,"|")
- I=I-1
- O=O-I:T=T-1
- For O
- str=str & Mid(txtArray(t),1+i,1)
- i=i+1
- EndWhile
- MessageBox str
- EndScript
復(fù)制代碼 (4)新建一個(gè)TXT文件
- set fso=CreateObject("Scripting.FileSystemObject")
- const forwriting=2
- const forreading=1
- set myfile=fso.createtextfile("路徑\文件名.txt")
復(fù)制代碼 (5)判斷一個(gè)文件是否存在
- IsFile = Plugin.File.IsFileExit("路徑\文件名.txt")
- If IsFile = True
- MessageBox "找到"
- Else
- MessageBox "沒(méi)找到"
- EndIf
復(fù)制代碼 (6)給TXT文件寫(xiě)入內(nèi)容
- set fso=CreateObject("Scripting.FileSystemObject")
- set myfile=fso.createtextfile("路徑\文件名.txt")
- myfile.writeline("內(nèi)容")
- Call Plugin.File.WriteFileEx("路徑\文件名.txt", "內(nèi)容")
復(fù)制代碼 (7)讀取TXT文件指定某一行內(nèi)容
- Text = Plugin.File.ReadFileEx("路徑\文件名.txt")
- txtArray=Split(Text,"|")
- // 顯示第5行,就寫(xiě) txtArray(4) 。 顯示第6行。就寫(xiě) txtArray(5)
- MessageBox txtArray(0)
復(fù)制代碼 (8)讀取TXT文件全部?jī)?nèi)容
- I=0
- Text = Plugin.File.ReadFileEx("路徑\文件名.txt")
- txtArray=Split(Text,"|")
- While Len(txtArray(I))>=1
- RE=RE & txtArray(I)
- I=I+1
- EndWhile
- MessageBox RE
復(fù)制代碼 (9)讀取txt文件一共多少行
- I=0
- Text = Plugin.File.ReadFileEx("路徑\文件名.txt")
- txtArray=Split(Text,"|")
- While Len(txtArray(I))>=1
- I=I+1
- EndWhile
- MessageBox i
復(fù)制代碼
|