PDA

View Full Version : Process each file in a folder


dafergu2
04-15-2011, 10:33 AM
I have a folder of sql scripts that need to be executed in a specific order. The order is based on a number that is at the beginning of the file name. For example:

100_Sql1.sql
200_Sql2.sql
4000_Sql3.sql
10000_Sql4.sql

Does VBP have a built in mechanism for something like this or do I need to write a script for this?

Thanks!

kinook
04-15-2011, 11:16 AM
The Process Files action always processes in sorted order (actually it's the order returned by FindNextFile, which is alphabetical on NTFS -- see http://msdn.microsoft.com/en-us/library/aa364428%28v=vs.85%29.aspx). One option would be to name the files so the sorted order is correct (i.e., by left-padding with zeros). The attached project would rename the files to sort properly.

Otherwise, you would need to manually sort (iterate with process files and store in sorted order) and then iterate over the sorted list.

dafergu2
04-15-2011, 11:21 AM
Thanks for the suggestions. The manual iteration is probably the best solution for us at this point. How would I tie that into the Process Files action?

dafergu2
04-15-2011, 12:36 PM
I've got a good first step at it. Another followup question...the rename action in the loop outputs its action step name every iteration of the loop.

Is there a way to disable actions from printing its exectution status?

For example...

4/15/2011 1:31:25 PM: Building project step 'Loop through temporary change script folder'...
4/15/2011 1:31:25 PM: Building project step 'Rename file'...
4/15/2011 1:31:25 PM: Building project step 'Loop through temporary change script folder'...
4/15/2011 1:31:25 PM: Building project step 'Rename file'...
4/15/2011 1:31:25 PM: Building project step 'Loop through temporary change script folder'...
4/15/2011 1:31:25 PM: Building project step 'Rename file'...
4/15/2011 1:31:25 PM: Building project step 'Loop through


When I have 229 files in my loop, it spams the log with a bunch of noise. Is there a way I can turn that off? I tried clicking Disable Action Output, but that did not work.

Thanks!

kinook
04-15-2011, 12:46 PM
Here's one way to do the sort (attached).

As far as log output, see Tools | User Options | Output -> Logging of step starting events (for the Output pane) or Tools | Application Options | Logging (More) -> Text Format Logging Options (for text log files).
http://www.kinook.com/VisBuildPro/Manual/outputuseropt.htm
http://www.kinook.com/VisBuildPro/Manual/loggingmoreopt.htm

dafergu2
04-15-2011, 01:03 PM
Awesome, thanks!!

Do the log settings work with the console application? We want to build a set of developer scripts using vbp and have them run via powershell.

We're planning on having the console vbp app run the build files from a scripts directory in our source. We were hoping to copy the console app to our svn tools dir so that we don't have to hardcode machine paths in our scripts.

I looked for the application config files in the specified folder:

C:\ProgramData\Kinook Software\Visual Build Professional 7

but the folder was empty.

kinook
04-15-2011, 01:38 PM
The console app output does not use the Application or User options (although this is on the todo list), but the log file output uses the App log settings whether built with the console or GUI app.

You can copy the console app to another folder and run from there. See here for where the application options get loaded from (the config file won't get created until changes are made to app options and VBP exits).
http://www.kinook.com/VisBuildPro/Manual/configurationfiles.htm