按willsort的建议我对此批处理修改了下并再次优化了一下,并扩充了合并同名文件的功能(因为最近有一堆C++的源代码,每个压缩包内都有一个readme.txt的说明文件,为了归类要一个个的打开readme.txt很烦,于是便扩充了合并同名文件的功能)
@echo off
cls
if "%1"=="/?" goto info
if "%1"=="-d" goto nottestafter
if "%1"=="-l" goto nottestafter
if "%1"=="-b" goto nottestafter
if "%3"=="" goto over
rem this equ "%1","%2","%3"=="" goto over
if "%4"=="" goto over
if "%5"=="/y" goto normal
if "%5"=="" goto normal
if not "%5"=="/n" goto useerr
goto normal
:normal
if not exist %4\nul md %4
:nottestafter
echo Copyright (R) By HuangShiquan 2005-2010 All Rights Reserved
if exist found$$.dat del found$$.dat>nul
echo Copyright (R) By HuangShiquan 2005-2010 All Rights Reserved>found$$.dat
echo Have found files for you as follows:
for /r %2 %%a in (%3) do echo %%~a &echo %%~a>>found$$.dat
if "%1"=="-m" goto domove
if "%1"=="-c" goto docopy
if "%1"=="-d" goto dodelete
if "%1"=="-b" goto dobinfile
if not "%1"=="-l" goto comerr
if "%4"=="" goto over
if "%4"=="/d" goto deldatforlist
if "%5"=="" goto over
if "%5"=="/d" del found$$.dat>nul
goto over
:dobinfile
if "%4"=="/y" goto dobinfilequiet
if "%5"=="/y" goto dobinfilequiet
echo Are you sure to Merge these file to %3 ?
echo You can Key (Ctrl+C) to Cancel the order, But if you put any key will Continue
pause>nul
:dobinfilequiet
if not exist %3 echo.>%3
for /f "skip=1 delims=" %%a in (found$$.dat) do echo Merge "%%~a" &© /y %3+%%a %3>nul
echo Have Merged these files Succeed to the %3
if "%4"=="/d" goto deldatforlist
if "%5"=="/d" goto deldatforlist
goto over
:deldatforlist
del found$$.dat>nul
goto over
:domove
if "%5"=="/y" goto normalquietmove
echo Are you sure to move these file ?
echo You can Key (Ctrl+C) to Cancel the order, But if you put any key will Continue
pause>nul
:normalquietmove
for /f "skip=1 delims=" %%a in (found$$.dat) do move /y "%%~a" %4 &echo Moving "%%~a"
echo Have moved these files Succeed to the directory
goto aboutdat
:dodelete
if "%4"=="/y" goto normalquietdelete
if "%4"=="/d" goto normaldelete
if not "%4"=="/n" goto deleteerr
:normaldelete
echo Are you sure to delete these file ?
echo You can Key (Ctrl+C) to Cancel the order, But if you put any key will Continue
pause>nul
:normalquietdelete
echo Please waite a while, I am working hard for you ...
for /f "skip=1 delims=" %%a in (found$$.dat) do del /f /s /q "%%~a">nul
echo Have deleted these files Succeed to the directory
if "%4"=="" goto over
if "%4"=="/d" goto deldatfordelete
if "%5"=="" goto over
if "%5"=="/d" del found$$.dat>nul
goto over
:deldatfordelete
del found$$.dat>nul
goto over
:docopy
if "%5"=="/y" goto normalquietcopy
echo Are you sure to copy these file ?
echo You can Key (Ctrl+C) to Cancel the order, But if you put any key will Continue
pause>nul
:normalquietcopy
echo Please waite a while, I am working hard for you ...
for /f "skip=1 delims=" %%a in (found$$.dat) do copy /y "%%~a" %4>nul
echo Have copyed these files Succeed to the directory
:aboutdat
if "%6"=="/d" del found$$.dat>nul
goto over
:deleteerr
echo.
echo Error: Can't delete these files for Syntax is illegal or bad used command
goto over
:comerr
echo.
echo Copyright (R) By HuangShiquan 2005-2010 All Rights Reserved
:deleteerr
echo.
echo Error: Syntax is illegal or not use a command Parameter
goto over
:useerr
echo.
echo Copyright (R) By HuangShiquan 2005-2010 All Rights Reserved
echo.
echo Error: option2 must use with option1 or Syntax is illegal
goto over
:info
echo.
echo Copyright (R) By HuangShiquan 2005-2010 All Rights Reserved
echo.
echo Usage: GetTypeFile (-command) (Para1) (Para2) (Para3)
echo.
echo Commands: -m to move these files; -c to copy these files;
echo -d to delete these files; -l only list these files;
echo -b to Merged these files.
echo Explain : Parameter1 the path for search;
echo Parameter2 the file name, you may then use wildcard (eg:*.*,
echo *.doc,filename.txt and so on);
echo Parameter3 the path for deposit;
echo Option : option1 /y do it quiet; /n inquire always
echo option2 /d not save moving data recorded file
echo Notice : option2 must use with option1,but Excepted when the command is
echo the letter of -d the letter of -b or the letter of -l.
echo Example: 1. "GetTypeFile -m j:\source *.txt e:\targe /y", it will move the
echo files which taken.txt as a suffix in drive(about j<img src="images/smilies/face-laugh.png" align="absmiddle" border="0"> to (j:\txt).
echo 2. "GetTypeFile -m j:\source *.txt e:\targe /y /d", it will move
echo the fileswhich taken .txt as a suffix in drive (about j<img src="images/smilies/face-laugh.png" align="absmiddle" border="0"> to the
echo directory (about j:\txt),and not save moving data recorded file.
echo 3. "GetTypeFile -l j:\source *.txt /y /d" or "GetTypeFile -l j:\
echo source *.txt /d", it will only list the,files which taken .txt as
echo suffix in drive (about j<img src="images/smilies/face-laugh.png" align="absmiddle" border="0">,and not save moving data recorded file.
echo 4. "GetTypeFile -b j:\source readme.txt /y /d" , it will Merge all
echo readme.txt documents in the catalogue and its subdivision at present
echo to big readme.txt documents.
echo.
<img src="images/smilies/face-surprise.png" align="absmiddle" border="0">ver
附:用
贴代码,效果确实不错啊!!!
Last edited by vptdosme on 2006-1-8 at 19:31 ]