asp批量读写更新文件utf-8编码文件示例

  asp批量处理文件,asp读utf-8文件,asp写utf-8文件示例代码,asp adodb.stream读写utf-8文件示例。asp批量处理目录文件示例代码

小提示:如果更新的是ansi编码的文件,只需要scripting.filesystemobject对象的opentextfile打开textstream数据流进行读写即可。如果是utf-8,只能使用adodb.stream进行操作,因为scripting.filesystemobject的charset只能指定为ascii,unicode和系统缺省编码(除非你系统缺省编码是utf-8,否则中文大陆内的大部分存储编码都是ansi)。

  asp批量处理目录下文件,更新文件内容示例代码

function readText(path,charset)'读文件
  set ts=server.CreateObject("adodb.stream")
  ts.charset=charset'内容编码
  ts.mode=3'读写模式
  ts.type=2'文本模式
  ts.open
  ts.LoadFromFile path
  readText=ts.readtext
  ts.close:set ts=nothing
end function
function writeText(path,charset,text)'写文件
  set ts=server.CreateObject("adodb.stream")
  ts.mode=3'写写模式
  ts.type=2'文本模式
  ts.open
  ts.charset=charset'内容编码
  ts.WriteText text,1
  ts.SaveToFile path,2
  ts.close:set ts=nothing
end function
function BulkUpdate(path)
  set fso=server.CreateObject("scripting.filesystemobject")
  set fd=fso.GetFolder(path)'获取文件夹对象
  set fls=fd.files'得到文件夹下所有文件
  for each fl in fls
    html=readText(fl.path,"utf-8")'注意你的文件编码,如果为ansi指定为gb2312,utf-8则为utf-8
	html=html&"中文内容"&now''''''你的修改逻辑,注意要修改这里
	writeText fl.path,"utf-8",html'写回文件
  next
  set fd=nothing
  set fls=nothing
  set fso=nothing
end function
BulkUpdate server.MapPath("html")

 

加支付宝好友偷能量挖...


原创文章,转载请注明出处:asp批量读写更新文件utf-8编码文件示例

评论(0)Web开发网
阅读(268)喜欢(0)Asp/VBScript