日期:2014-05-20  浏览次数:20808 次

用bat批处理jar的菜鸟问题
小弟今天刚开始试着写bat文件,进行批处理,有个很简单的问题想请教各位

以下为刚写的startup.dat,如运行C:\>startup.bat "a.txt" "b.txt"可批处理两个文件:

@echo off

set taskName=%1

set taskName2=%2

set tempclasspath=%CLASSPATH%

set CLASSPATH=%CLASSPATH%;.\lib\dom4j-1.6.1.jar;.\*ToolKit.jar;

java *ToolKit.*Code %taskName% %taskName2%

set CLASSPATH=%tempclasspath%

@echo

但是如果我想我想批处理的文件个数不确定
比如运行C:\>startup.bat "a.txt" "b.txt" "c.txt" "d.txt" .... "*.txt"

那bat应该怎么写呢?是用for循环吗?怎么用呢?
@echo off  
type %1  
type %2  
type %3  
type %4
。。?

------解决方案--------------------
BatchFile code
@echo off
setlocal enabledelayedexpansion
set PRO_HOME=E:\temp\program
set LIB_PATH=.;%PRO_HOME%\conf
for /f %%i in ('dir %PRO_HOME%\lib\*.jar /b') do (
  set LIB_PATH=!LIB_PATH!;%PRO_HOME%\lib\%%i
)
echo ==================================================================
echo java -cp %LIB_PATH% com.test.Main %*
echo ==================================================================
java -cp %LIB_PATH% com.test.Main %*
echo on