繁体   English   中英

如何使用Windows批处理命令一次在c,d,e驱动器的所有目录中搜索文件

[英]how to search file(s) in all the directories of c,d,e drives at a time using windows batch commands

手动地,我试图在PC中搜索病毒。 作为其中的一部分,我编写了一个Windows批处理脚本,如下所示。

@echo off

.....

:start

IF EXIST pathoengs.exe goto infected

IF EXIST pathoengs.bat goto infected

IF NOT EXIST pathoengs.bat goto statistics

IF NOT EXIST pathoengs.exe goto statistics

set Pathname="C:\"

CD %Pathname%

:infected

echo A Virus has been detected!

set /p n=Delete?(y/n)

If %n% == y del pathoengs.bat del pathoengs.exe

If %n% == n goto exit

goto start

:statistics

echo No virus

:exit

exit

问题是,我的脚本无法检测C:\\驱动器或C:\\驱动器的子文件夹中存在的文件。

如果我在C:\\ Users \\ xxx \\ Desktop之类的路径而不是CD C:\\中搜索文件,并在脚本中将其写为“ CD C:\\ Users \\ xxx \\ Desktop”,则它的搜索和运行状况都很好预期。 我不明白,如果尝试在CD CD:\\之类的C驱动器中进行搜索,为什么会失败。 我在这里做错了吗,还是搜索代码本身的脚本是错误的。 可能是搜索所有驱动器及其子文件夹的方式不同,请让我知道您的建议。

实际上,我想在所有驱动器(如c,d,e ..)及其子文件夹中搜索文件。 如果文件存在,则说明病毒存在。 因此,用户将转到并删除文件,然后继续进行。 否则,不存在病毒。

如果您有任何想法,请让我知道如何使用Windows批处理脚本实现这种搜索。 请只做那些需要的。

请告诉我您是否需要更多信息。

谢谢。

这应该为您提供一个文件,其中包含许多驱动器上的所有那些文件名,然后您可以阅读该文件以执行所需的操作。

它不能避免检查DVD驱动器等,而且速度很慢,因为它必须检查每个驱动器的每个部分。

@echo off
(
   for %%a in ( c d e f g h i j k l ) do (
      if exist "%%a:\" dir "%%a:\pathoengs.exe" "%%a:\pathoengs.bat" /b /s /a-d
   )
)>"%temp%\virus list.txt"
set /p n=Delete?(y/n)

If %n% == y del pathoengs.bat del pathoengs.exe

If %n% == n goto exit

您没有在两个del命令之间放置& ,脚本应如下所示:

choice /c:yn /m "Delete?(y/n)"

If %errorlevel% == 1 del pathoengs.bat & del pathoengs.exe

If %errorlevel% == 2 exit /b

使用choice /c更好,而使用exit /b代替。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM