感谢提醒,用循环是不得以而为之,我只是想抛砖引玉。。。
看了各位高手的贴,收获不小,为此我将自己写的一个垃圾批处理与大家共享:
(还望高手指教)
@echo off
cls
if "%1"=="/?" goto info
if "%1"=="" goto over
if "%2"=="" goto over
if "%3"=="" goto over
if "%1"=="-d" goto nottestafter
if "%1"=="-l" goto nottestafter
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 Please waite a while, I am working hard for you ...
for /r %2 %%a in (%3) do echo %%~a>>found$$.dat
echo Have found files for you as follows:
for /f "skip=1 tokens=1 delims=" %%a in (found$$.dat) do echo %%a
if "%1"=="-m" goto domove
if "%1"=="-c" goto docopy
if "%1"=="-d" goto dodelete
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
: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
echo Please waite a while, I am working hard for you ...
for /f "skip=1 delims=" %%a in (found$$.dat) do move /y "%%~a" %4
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 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 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

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

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

,and not save moving data recorded file.
echo.

ver
说明:不知为何,有些批处理字符变成了图像,如:“

ver”
[
Last edited by vptdosme on 2006-1-7 at 23:38 ]