从文本文件读取后删除行 [英] Delete line after reading from text file
本文介绍了从文本文件读取后删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让这个脚本在阅读完每一行文本后删除它,而不是直接进入下一行并将其保留在文本文件中.
How do I get this script to delete each line of text after reading it instead of just going onto the next one and still leaving it in the text file.
我能做些什么来改变它?
What can I do to change it?
Dim fso
Set objEmail = CreateObject("CDO.Message")
objEmail.From = """UPS"" <User@Example.com>"
objEmail.Subject = "This is a test"
Const ForReading=1
Set fso = CreateObject("Scripting.FileSystemObject")
Set dict = CreateObject("Scripting.Dictionary")
BodyText = fso.OpenTextFile("C:\Users\User\Desktop\UPS-Email.htm",ForReading).ReadAll
objEmail.HtmlBody = BodyText
'objEmail.AddAttachment "C:\Users\User\Desktop\test.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set dict = CreateObject("Scripting.Dictionary")
Set file = fso.OpenTextFile ("C:\Users\User\Desktop\e.txt", 1)
row = 0
Do Until file.AtEndOfStream
line = file.Readline
dict.Add row, line
row = row + 1
objEmail.To = line
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "127.0.0.1"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
Loop
推荐答案
您无法在阅读文件时从文件中删除内容.您可以做的是在完成阅读后截断文件:
You can't delete content from a file while you're reading the file. What you can do is truncate the file after you finished reading from it:
Do Until file.AtEndOfStream
...
Loop
file.Close
fso.OpenTextFile("C:\Users\User\Desktop\e.txt", 2).Close
这篇关于从文本文件读取后删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文