honghunter 发表于 2009-1-21 18:20:34

文本读写的问题

我的目的是想要截取log文档最后面的 $checkLine行文本,然后收尾加点内容,变成html。
遇到的问题是,产生的 index.html 中,始终没有 $htmlFoot 中的哪些内容。

恳请各位不吝指教,谢谢!

;~         Defult value
    $fileName = "D:\tenwa\log\jk_log.log"
        $outFileName = "D:\Lotus\Domino\data\domino\html\tmphtml\index.html"
        $checkLine = 500
        $sleepTime = 5
        $strURL = "http://172.16.80.25/tmphtml/index.html#end"

$htmlHead = "<html><HEAD>" & @CRLF
$htmlHead = $htmlHead & "<TITLE>interface log, " & $sleepTime & "' refresh </TITLE>" & @CRLF
$htmlHead = $htmlHead & '<META HTTP-EQUIV="REFRESH" CONTENT="' & $sleepTime & '; URL=' & $strURL & '">' & @CRLF
$htmlHead = $htmlHead & "</HEAD><body><pre>" & @CRLF

$htmlFoot = '<a href="" name="end"></a>' & @CRLF
$htmlFoot = $htmlFoot & "</pre></body></html>" & @CRLF

$fileLineCount = _FileCountLines($fileName)
    $skipLine =0
   
    if $fileLineCount > $checkLine Then
            $skipLine = $fileLineCount - $checkLine
    endif   

    $fileBody = ""
   
    $N = FileGetSize($fileName) - 1
    $M= ""
        If @error Or $N = -1 Then
;~           skip
        Else
                $file = FileOpen($fileName, 0)
                $M=FileRead($file)
                FileClose($file)
               
                $M=StringReplace($M,@CRLF,@CR)
                $M=StringSplit($M,@CR)
       
                For $i =$M - $checkLine to $M
                        $fileBody = $fileBody & $M[$i] & @CRLF       
                Next

                $outFile = FileOpen($outFileName, 2)
                FileWrite($outFile, $htmlHead & $fileBody & $htmlFoot)
                FileClose($outFile)
    EndIf

liongodmien 发表于 2009-1-22 13:26:36

分次写入一试

honghunter 发表于 2009-1-23 07:39:34

谢谢楼上的答复。

你的意思是否是将
FileWrite($outFile, $htmlHead & $fileBody & $htmlFoot)

修改成多个 FileWrite?
页: [1]
查看完整版本: 文本读写的问题