Process file with for command in alphabetical order

二次信任 提交于 2019-12-11 02:52:01

问题



I must run n query SQL for update more database. I created a batch file to help me in this activity but the queries are not executed ordered by name.

I use this batch command:

for %%I in (.\*.sql) DO sqlcmd -S .\istance -U username -P password -d dbname -i %%I -o .\%%I.log

How can I run all queries ordered by name?
Thanks for your answer.

Note: I use Windows 7.


回答1:


Only reason for the FOR command not enumerating files in name order is that the file system is not NTFS. FAT filesystem enumerate files in drop order.

So use explicit name order enumeration

for /F "tokens=*" %%i in ('dir /b /on *.sql') do (
    sqlcmd -S .\istance -U username -P password -d dbname -i %%i -o .\%%i.log
)


来源:https://stackoverflow.com/questions/19364670/process-file-with-for-command-in-alphabetical-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!