本帖最后由 tmplinshi 于 2015-3-19 18:57 编辑
- :: do.bat
-
- @echo off
-
- if "%~1" == "" goto help
- if "%~1" == "/?" goto help
-
- :main
- setlocal
- set args=%*
- if /i "%~1" == "-f" set args=%args:*-f =%
- set "var=%args:"=|%"
- if "%var:~0,1%%var:~-1%" == "||" set "args=%args:~1,-1%"
-
- (
- for /f delims^=^ eol^= %%a in (' findstr .* ') do %args%
- ) || (
- if /i "%~1" == "-f" (
- for /f "tokens=*" %%a in (" ") do %args%
- )
- )
- exit /b
-
- :help
- echo do.bat - 在管道符后面使用 do
- echo,
- echo 用法: ^<命令^> ^| do [-f] ^<命令^>
- echo,
- echo -f 强制执行。(即使 stdin 是空的,也依旧执行)
- echo,
- echo 示例:
- echo,
- echo 1. 查找包含字符串 str 的文件,并移动到文件夹 _dir
- echo findstr /m "str" * ^| do move "%%a" "_dir\"
- echo 2. 如果命令中含有特殊字符,需要用双引号括起来
- echo echo test ^| do "echo %%a & echo END"
- echo 3. -f 参数使用示例
- echo cd . ^| do -f echo "%%a"
- exit /b
复制代码
|