开发者

sql deploy with dos

How can I customize the the FOR command below to loop through the files inside the Database folder fol开发者_如何转开发lowing the order of the number prefixed in the file name?

FOR /R ../Database %%f IN (*.sql) DO sqlcmd -S %1 -d %2 -U %4 -P %5 -i "%%~f" >> Logs/%2_DBInstall.log || goto errors

Database folder contains: 001_usp_procedure1.sql 002_ups_procedure2.sql

Thanks very much,


Please try the following

del temp.txt
del temp1.txt
for  /F "usebackq "  %%F IN (`dir /b /s /o:n "../Database/*.sql"`)  DO (
echo %%~nF  / %%F >> temp.txt
)
sort temp.text temp1.text
for /F "tokens=1,2 delims=/" %%i IN (temp1.txt) DO sqlcmd -S %1 -d %2 -U %4 -P %5 -i "%%j" >> Logs/%2_DBInstall.log || goto errors

It should work for recursive directories too (process is sorted by global filename without taking account of the path ... did I understand the problem?) Please note that two temp files are being used. Be careful with the names (or use real temp files)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜