找回密码
 加入
搜索
查看: 1117|回复: 1

如何删除一个文件文件里所在的行(连带这一行号)

[复制链接]
发表于 2009-12-14 15:23:17 | 显示全部楼层 |阅读模式
本帖最后由 boyhong 于 2009-12-14 18:01 编辑

很痛苦。我现在检测到HOSTS文件里有:
12.12.12.12   www.xxxx.com.cn
这一行时,我只是拿一个""去替换掉这串字符,有没有办法将这一行彻底删除呀?
#include <file.au3>
jctcohosts()

Func jctcohosts()
Dim $ajcRecords
If Not _FileReadToArray(@WindowsDir&"\system32\drivers\etc\hosts",$ajcRecords) Then
   MsgBox(4096,"Error", " 没有找到HOSTS文件     错误代码是:" & @error)
   Exit
EndIf

For $jx = 1 to $ajcRecords[0]
        if  $ajcRecords[$jx] ="12.12.12.12   www.xxxx.com.cn" Then
                _FileWriteToLine(@WindowsDir&"\system32\drivers\etc\hosts",$ajcRecords[$jx], "", 1)
         EndIf         
Next
EndFunc

评分

参与人数 1金钱 +8 收起 理由
afan + 8 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2009-12-14 15:35:42 | 显示全部楼层
本帖最后由 netegg 于 2009-12-14 16:02 编辑

_filereadtoarray($file, $aAarry)
$iIndex = _arraysearch($aArray, $text, 0, 0, 0, 1)
$file = fileopen($file,2)
_filewritefromarray($file, _arraydelete($aArray, $iIndex))
fileclose($file)

评分

参与人数 1贡献 +1 收起 理由
boyhong + 1 感谢netegg兄。

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-2 05:10 , Processed in 0.081382 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表