Board logo

标题: 怎样按照指定的输入复制指定的文件 [打印本页]

作者: yaya2006     时间: 2006-11-17 22:29    标题: 怎样按照指定的输入复制指定的文件

我有道批处理的程序编不出来了,请教一下:当输入a时,从指定位置或输入的参数位置拷贝一个文件;当输入b时,把c盘的txt文件,文件名及内容显示出来。我想了好久还是不能理解

[ Last edited by namejm on 2006-11-22 at 06:37 PM ]
作者: NaturalJ0     时间: 2006-11-17 23:04
你可以查看下 CHOICE 这个命令,应该能帮上你。
附件 1: choice.zip (2006-11-17 23:04, 17.97 K, 下载附件所需积分 1点 ,下载次数: 12)

作者: hxuan999     时间: 2006-11-23 00:35
随便写了一个,知道你要的是不是这个效果.

  Quote:

  1. @echo off

  2. :in
  3. echo.
  4. set /p in="Input a or b ...  (X=exit)   >  "
  5. if "%in%"=="" goto in
  6. if "%in%"=="x" goto end
  7. if "%in%"=="X" goto end
  8. if "%in%"=="a" goto a
  9. if "%in%"=="A" goto a
  10. if "%in%"=="b" goto b
  11. if "%in%"=="B" goto b
  12. goto in

  13. :a
  14. set /p infile="Input a file, path and name ...  "
  15. if "%infile%"=="" goto a
  16. if exist "%infile%" (
  17.     copy /y "%infile%" c:\
  18. ) else (
  19.     echo "%infile%" is not exist!
  20. )
  21. goto in

  22. :b
  23. for /f "usebackq" %%f in (`"dir /b c:\*.txt"`) do (
  24.     echo ----[%%f]----
  25.     type "c:\%%f"
  26. )
  27. goto in

  28. :end
  29. exit 0
        hxuan?表ー:  2006-11-22  11:35

[ Last edited by hxuan999 on 2006-11-22 at 12:40 PM ]