~~~~怎么用.bat文件删去指定的文件夹内容?~~~~

来源:百度知道 编辑:UC知道 时间:2024/05/21 16:57:29
下面的代码是
将C盘的那个域名解析文件(hosts)里添加一个域名和解析到127.0.0.1

echo.>>%windir%\system32\drivers\etc\hosts
echo 127.0.0.1 www.xxxxxx>>%windir%\system32\drivers\etc\hosts

但是怎么删除呢?
简单说删127.0.0.1 www.xxxxxx的bat代码是什么?

@echo off
type %windir%\system32\drivers\etc\hosts | findstr /v /c:"127.0.0.1 www.xxxxxx" >%windir%\system32\drivers\etc\hosts_
move %windir%\system32\drivers\etc\hosts_ %windir%\system32\drivers\etc\hosts
pause

这个问题我考虑很久了,我所想到的方法都是一些很麻烦的方法。
你可以试试 用for命令把每一行都定义到一个变量,再用if命令判断是不是要删除的那一行,不是就导出到另一个文件。最后把源文件删除,把新文件命名成hosts即可实现。不过比较麻烦。