我正在编写一个备份脚本来进行备份。
它需要复制"主机"具有以下条件的文件: "如果系统"托管"文件包含任何未注释的条目,然后复制它"。
有什么想法吗?
答案 0 :(得分:0)
作为注释行,在主机文件上以此"#"
字符串开头,因此,
您应该使用Find /V "#"
显示所有不包含指定字符串"#"
有关 Find /?
的更多帮助您可以这样做:
@echo off
Rem Batch script to copy uncommented entries of your hosts file
set "BackupHostsFile=%userprofile%\Desktop\BackupHostsFile.txt"
If Exist "%BackupHostsFile%" Del "%BackupHostsFile%"
set "hostspath=%windir%\System32\drivers\etc\hosts"
Rem Find /V "#" : To display all lines NOT containing the specified string "#"
for /f "delims=" %%a in ('Type "%hostspath%" ^| find /v "#"') Do (
If Not %%a=="" echo %%a >> "%BackupHostsFile%"
)
Start "" "%BackupHostsFile%"