2015-02-11 193 views
0

我想从源文件复制到目的地只有.txt扩展名的文件。我想在命令行中给出参数路径名称 - source和路径名称 - destination。这里是我的批处理文件Script.bat:批处理文件 - 传递路径名称作为参数在命令行中

@ECHO OFF 
setlocal 
set /p source = 
set /p destination= 
FOR %%f IN (*.txt) DO XCOPY "%source%"\"%%f" "%destination%" /m /y /d /s 

我要调用此批处理文件在cmd中这样:

cmd> Script.bat "SourceFolder" "DestinationFolder" 

但它不工作! 谢谢!

+0

为什么当XCOPY作品'XCOPY下的批处理文件:\源\ *。 txt c:\ dest'或[Robocopy](http://www.computerhope.com/robocopy.htm)'robocopy c:\ hope c:\ hope2 * .txt'? – ziddarth 2015-02-11 20:23:00

回答

0

假设的正确性这个脚本可以工作:

@echo off 
setlocal 
if "%~1"=="" goto :error empty 1 
if "%~2"=="" goto :error empty 2 
set "source=%~1" 
if not exist "%source%\" goto :error not exist 1 
set "destination=%~2" 
if not exist "%destination%\" goto :error not exist 2 
xcopy "%source%\*.txt" "%destination%\" /m /y /d /s 

goto :eof 
:error 
echo wrong parameters %* 
goto :eof 

参见下一个资源:Command Line arguments (Parameters)

1

试试看。这可能不完全正确,但它可以帮助你开始。 /m /y /d /sxcopy开关

@echo off 
setlocal 
set /p source = 
set /p destination= 
xcopy /m /y /d /s "%~source%\*.txt" "%~destination%\"