[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 【已结】批处理侦测每个盘是否有autorun.inf 若有set 其内容

以下是小弟写的代码:
  1. @echo off
  2. for %%i in (c d e) do (if exist %%i: (if exist %%i:\autorun.inf (for /f %%j in ('type %%i:\autorun.inf') do (call set autorun_txt=%%autorun_txt%% %%j))
  3. echo %%i:\autorun.inf
  4. echo.
  5. echo %autorun_txt%
  6. ))
  7. pause
复制代码
流程是:
(1) 侦测c: d: e: 是否存在
(2) 若存在 c: d: e: 则再侦测 各盘是否有 autorun.inf文件
(3) 若有 则将autorun.inf内容设为%autorun_txt%变数
(4) 显示 %autorun_txt%的值

可是不成功~小弟觉得应该是2层for 导致延迟变量的问题,请问应该怎么改?
ps. 流程一定要用2层for,小弟不希望改成1层for 直接来侦测各盘是否有autorun.inf
      因为小弟想学习延迟变数...而我写了这程序却无法使用,想了解详细原因

[ 本帖最后由 strong12345 于 2009-3-2 09:35 编辑 ]

不管代码对错,建议使用缩进,比如:
  1. @echo off
  2. for %%i in (c d e) do (
  3.   if exist %%i: (
  4.     if exist %%i:\autorun.inf (
  5.       for /f %%i in ('type %%i:\autorun.inf') do (
  6.         call set autorun_txt=%%autorun_txt%% %%i
  7.       )
  8.     )
  9.     echo %%i:\autorun.inf
  10.     echo.
  11.     echo %autorun_txt%
  12.   )
  13. )
  14. pause
复制代码
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

原帖由 strong12345 于 2009-2-20 12:17 发表
以下是小弟写的代码echo off
for %%i in (c d e) do (if exist %%i: (if exist %%i:\autorun.inf (for /f %%j in ('type %%i:\autorun.inf') do (call set autorun_txt=%%autorun_txt%% %%j))
echo %%i:\autorun ...

早前在下寫了個類似的批次,從中抽一段有關找inf文件的放上來
::================================================================
for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
      if exist %%a:\*.inf (
      echo ▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅▅ >>TaurusInfLog.txt
      echo. >>TaurusInfLog.txt
      echo              ╔═══════════╗>>TaurusInfLog.txt
      echo              ║   #Partition[%%a:]    ║>>TaurusInfLog.txt
      echo              ╚═══════════╝>>TaurusInfLog.txt
      echo ▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂  >>TaurusInfLog.txt
      echo [The [.inf] file/s under partition [%%a:\] includes]: >>TaurusInfLog.txt
      echo == == == == == == == == == == == == == == == == == = >>"TaurusInfLog.txt"
             for /f %%i in ('Dir /a:h-d /b %%a:\*.inf') do (
             echo  ^<INF^>^<H^>------------^> %%i>>"TaurusInfLog.txt"
             )
             for /f %%i in ('Dir /a:d /b %%a:\*.inf') do (
             echo  ^<DIR^>-----------------^> %%i>>"TaurusInfLog.txt"
             )
             for /f %%i in ('Dir /a:-d-h /b %%a:\*.inf') do (
             echo  ^<INF^>-----------------^> %%i>>"TaurusInfLog.txt"
             )
      echo ▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ >>"TaurusInfLog.txt"
             if exist %%a:\Autorun.inf (
             echo                [Autorun.inf content] >>"TaurusInfLog.txt"
             echo == == == == == == == == == == == == == == == == == = >>"TaurusInfLog.txt"
             type %%a:\Autorun.inf >>"TaurusInfLog.txt"
             echo.>>"TaurusInfLog.txt"
             )
         )
     ) >nul 2>nul
if not exist TaurusInfLog.txt goto Err
@cls
@echo           Find ^<.INF^> ●
@goto :reg
:Err
cls
@echo           Find ^<.INF^> ●
::================================================================

[ 本帖最后由 Taurus 于 2009-2-22 03:38 编辑 ]
1

评分人数

TOP

返回列表