1. 程式人生 > >bat指令碼讀取配置檔案

bat指令碼讀取配置檔案

bat 讀取配置檔案 @echo off :: echo please input(is not null):user passsword expath date :: 讀取配置檔案 where bcp ::正式有bcp放開下面這句話 ::if "%errorlevel%"=="1" (exit) else (echo Program exists) for /f "tokens=1,2 delims==" %%i in (config.properties) do ( if "%%i"=="user" set user=%%j if "%%i"=="password" set password=%%j if "%%i"=="expath" set expath=%%j if "%%i"=="date" set date=%%j if "%%i"=="ip" set ip=%%j if "%%i"=="tables" set tables=%%j if "%%i"=="database" set database=%%j ) ::if "%1"=="" (echo user不能為空) else (set user="%1") ::if "%2"=="" (echo password不能為空) else (set password="%2") ::if "%3"=="" (echo expath不能為空) else (set expath="%3") ::if "%4"=="" (set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%") else (set Ymd="%4") ::if "%5"=="" (echo table不能為空) else (set table="%5") ::rem FOR %%C IN (*.BAT *.TXT *.SYS) DO TYPE %%C ::rem 表示此命令後的字元為解釋行(註釋) ::rem set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%" ::rem set "user=%1" ::rem set "password=%2" ::rem set "path=%3" echo user:%user% echo password:%password% echo expath:%expath% echo date:%date% echo database:%database% echo ip:%ip% ::rem echo %errorlevel% 程式錯會返回1,成功為0 echo %tables% ::for %%i in (%tables%) do bcp "select * from %database%.dbo.%%i;" queryout %expath%\%%i.txt -S %ip% -U %user% -P %password% -c for %%i in (%tables%) do echo "bcp select * from %database%.dbo.%%i; queryout %expath%\%%i.txt -S %ip% -U %user% -P %password% -c" pause>nul