
求批處理for命令里操作比較形式變量報錯的問題想寫一個查詢指定目錄下所有的makefile所在路徑,并且要過濾一些文件夾,但是按照如下方式寫,就會提示此處不應有!=,錯誤代碼為!file:debug=! NEQ %%i
如果換下面這種寫法就可以:nclick="copycode($('code0'));">復制代碼
- @echo off
- setlocal EnableDelayedExpansion
- set rootpath=C:SourceReposserver
- cd /d %rootpath%
- for /r %rootpath% %%i in (Makefile) do (
- set file=%%i
- if !file:debug=! NEQ %%i echo !file!
- )
- pause
- endlocal
這里我沒搞懂直接比較為什么會報錯,為什么將 !file:debug=! 賦給另一個變量后再比較就沒問題了,請大佬們幫忙指導一下,我是剛開始學bat,對for循環里的形式變量%%i 的操控比較迷惑nclick="copycode($('code1'));">復制代碼
- @echo off
- setlocal EnableDelayedExpansion
- set rootpath=C:SourceReposserver
- cd /d %rootpath%
- for /r %rootpath% %%i in (Makefile) do (
- set file=%%i
- set tmp=!file:debug=!
- if !file! EQU !tmp! echo !file!
- )
- pause
- endlocal

