Hi,
I am in the middle of writing a DOS batch file that will be used to loop through all tables in a database to truncate them. I have never used DOS before and have searched all over the internet but am struggling on how I would loop through the results from the "Show tables" results. I have read that DOS does not support arrays and could only loop through a list.
Can anyone help with how I would exactly do this?
Many thanks in advance
How to loop through the results from "show tables"
Moderator: DosItHelp
Post
Just use:That will loop the script, if that's what you wanted
Code: Select all
:start
some codes and stuff here
goto start
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
If you're generating a list somehow, you'll probably want to use the FOR command to do something to each item in the list. Like this:
If your list is in a file:
If your list is generated by another command, then you can either redirect that list to a file:
and then work with the for statement, or you can attempt to work directly with the output:
Maybe that helps? Or perhaps you could be more clear on what you need.
If your list is in a file:
Code: Select all
for /f "delims=" %%a in (file.txt) do (
echo The current line in the txt file is %%a.
do whatever else you want using %%a as the line from the text file.
)
If your list is generated by another command, then you can either redirect that list to a file:
Code: Select all
sqlcmd (something that generates output) > file.txt
and then work with the for statement, or you can attempt to work directly with the output:
Code: Select all
for /f "usebackq delims=" %%a in (`sqlcmd "something here"`) do (
echo Same as above %%a
)
Maybe that helps? Or perhaps you could be more clear on what you need.