如何在多个目录中搜索(How search in multiple directories)
的start.bat
@echo off CALL bat.bat "C:\Users\admin\Documents\test 2,C:\Users\admin\Documents\test 1" "*.xml *.txt *.html" "D:\Work\bat\batLog.txt"bat.bat
for %%G in (%1) do ( echo %%~G pushd "%%G" If Exist "%%G" ( for /R %%H in ("%2") do ( if %%~zH LSS %3 ( >>"%4" ( echo %%~H echo %%~tH for /f "tokens=* delims=," %%i in ('type "%%~H"') do ( echo %%i ))) popd))) pause exit/b为什么不去下一个目录? 回声只测试2
start.bat
@echo off CALL bat.bat "C:\Users\admin\Documents\test 2,C:\Users\admin\Documents\test 1" "*.xml *.txt *.html" "D:\Work\bat\batLog.txt"bat.bat
for %%G in (%1) do ( echo %%~G pushd "%%G" If Exist "%%G" ( for /R %%H in ("%2") do ( if %%~zH LSS %3 ( >>"%4" ( echo %%~H echo %%~tH for /f "tokens=* delims=," %%i in ('type "%%~H"') do ( echo %%i ))) popd))) pause exit/bwhy does not it go to the next directory? Echo only test 2
最满意答案
现在使用您的新代码完全重写。 这可以让你更接近你想做的事情。 希望我修复了你的程序中的所有其他错误。 我故意缩进我的代码,以便我可以看到代码块开始和结束的位置。 更容易看到和理解代码是如何工作的。
的start.bat
@echo off call bat.bat "C:\Users\admin\Documents\test 2,C:\Users\admin\Documents\test 1" "*.xml *.txt *.html" "20000" "D:\Work\bat\batLog.txt"bat.bat
@echo off REM %1 = List of Folders REM %2 = List of file masks REM %3 = File Size for comparison REM %4 = Log File set "folders=%1" set "folders=%folders:,=","%" for %%G in (%folders%) do ( echo %%~G If Exist "%%~G" ( pushd "%%~G" for /R %%H in (%~2) do ( if %%~zH LSS %~3 ( >>"%~4" ( echo %%~H echo %%~tH for /f "tokens=* delims=," %%I in ('type "%%~H"') do ( echo %%~I ) ) ) ) popd ) ) pause exit/bThis is now a complete rewrite using your new code. This should get you closer to what you want to do. Hopefully I fixed all the other errors with your program. I purposely indent my code so that I can see where a code block begins and ends. Much easier to see and understand how the code is working.
start.bat
@echo off call bat.bat "C:\Users\admin\Documents\test 2,C:\Users\admin\Documents\test 1" "*.xml *.txt *.html" "20000" "D:\Work\bat\batLog.txt"bat.bat
@echo off REM %1 = List of Folders REM %2 = List of file masks REM %3 = File Size for comparison REM %4 = Log File set "folders=%1" set "folders=%folders:,=","%" for %%G in (%folders%) do ( echo %%~G If Exist "%%~G" ( pushd "%%~G" for /R %%H in (%~2) do ( if %%~zH LSS %~3 ( >>"%~4" ( echo %%~H echo %%~tH for /f "tokens=* delims=," %%I in ('type "%%~H"') do ( echo %%~I ) ) ) ) popd ) ) pause exit/b更多推荐
发布评论